1

I have what ought to be a very simple issue, but I can't seem to solve it.

I have a master/detail report. It's actually two reports. One for the master records and then a subreport for the details. This is actually in Dynamics AX (which is why this setup and some of the limitations I'll describe may seem a bit odd). But the issue I'm having is an SSRS issue.

Because of the way the Dynamics AX stuff is set up, my reports are based on 2 tables. Table 1 is a 'select * from table1' and Table 2 is 'select * from table2'. For reasons of the way it's setup in AX, there is no where clause. It's simply reporting off of the full contents of these tables.

Product Availability

So this is my setup for the first table. The products list and then the row below has the subreport.

The second table is as follows:

Table 2 details

Table 2 has the details, which are orders that have that product on them. What we're trying to do is see how many cases we have orders for, versus what we have in stock.

Table 2 has all the data for all the products. The query that the subreport is based on is select * from table2. There is no where clause (this is based on how it's set up in AX. I can't filter in the where clause, in this case).

So to handle the filtering, I create the group on ProductCode and then add this filter:

Product Code Filter

Up to this point, everything in my report works perfectly. It displays everything exactly the way I want. My details list all the orders associated with each product.

The trick now is that I want a sub-total in the details of all the cases ordered for that product. But nothing I do seems to work right.

If I simply right click on the OrderQty field for the details and click "Add Total", it gives me the total of all products from all orders, in each subreport. So, for example, a detail list for a product might show 2 order with quantities of 100 and 20 and should show a subtotal of 120, but instead shows a subtotal of say 40,000, which would be the sum of all the details for all the products in the report. And it will show that same 40,000 subtotal in every detail list for every product.

Alternatively, if I add a row inside the group, after, and add a Sum() for the CaseCount, after each individual detail row, it gives me a subtotal that matches the count of the detail row. So, for example, I might have Product 130 with 2 orders, for 120 and 20. Each row will have a subtotal. The first, with 100, and the second with 20, instead of a single subtotal after both rows, of 120.

This seems like it ought to be ridiculously simple, but I'm stumped.

I would ask that you try to provide a solution that doesn't require re-architecting the report as a whole, if possible. We're on a time crunch here and that would cause some problems.

No doubt I'm missing some key info, so please let me know what else you might need to know to help me solve this.

Update

Chance Finley below suggested Sum(field, groupname), and I tried that. It actually does the sum properly, but it displays it improperly.

Report with sum of group

Here's what it looks like in Visual Studio...

SSRS Designer Layout

Update 2

If I add the total outside the group, as shown here:

Outside Group

I get the following results:

Outside group totals

Which puts my sum right where I want it, but it's counting all the products.

Update 3

And here's another one. This one gives the right results, but then throws in other stuff at the end that I don't want. Here's the setup in the SSRS designer: Between two groups

And here's how it comes out: Between two groups totals After showing all the subtotals, it then shows second product (0227) and then shows a list of all the subtotals that follow it (except missing 0130). The third shows all subtotals except 0130 and 0227.. And so on...

Update 4

Following the steps provided by CuriousKid, I got closer...

The setup following his steps (not all fields filled in yet): Almost

And the results:

Almost totals

Problem is that it's all product results shown in details under each product.

Pete
  • 6,585
  • 5
  • 43
  • 69
  • Are the rows grouped on OrderNumber? The scope of the `Sum` function is based on the groups it's in. – StevenWhite Jul 31 '17 at 15:51
  • That's how it's acting, but no, the rows are grouped on product number. – Pete Jul 31 '17 at 16:20
  • I think your scope of the sum expression is Product and Order. I would suggest to go to your ProductGrouping --> click on down arrow --> add Total --> After. This should give you what you want but for some reason if it is not showing it properly then add your sum expression in the new sum line created. Hopefully this will work. – CuriousKid Jul 31 '17 at 17:51
  • @CuriousKid Unfortunately, this too results in the 43,064 subtotal for every item (as shown in Update 2 above)... – Pete Jul 31 '17 at 18:30
  • Can you show us the Row Groups you have? – CuriousKid Jul 31 '17 at 18:39
  • Well, it's varied depending on which example you see. The main row groups is called Details1 and it has the filter shown in the group properties above. For some of the examples, I've created a parent group of Details1 called ProductCode which also groups on ProductCode – Pete Jul 31 '17 at 19:00
  • put the filter on the productcode and not in details1. Check my answer below. – CuriousKid Jul 31 '17 at 19:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150655/discussion-between-curiouskid-and-pete). – CuriousKid Jul 31 '17 at 19:07

3 Answers3

3

Here is what you need to do. Please check if any of the config is missing in your design.(I feel there is some issue in your grouping config but cannot verify without the row group details provided in the Question)

Step 1:

Add the columns:

enter image description here

Step 2:

Add ParentGroup to the "(Details)", and group it by ProductCode.

enter image description here

enter image description here

You will get this:

enter image description here

Step 3:

enter image description here

This will give you sum row of details row group (in this case which is Quantity)

enter image description here

Final Answer: With all the "ProductCode"

enter image description here

With Filtered "ProductCode"

Adding filter on the ProductCode Group:

enter image description here

enter image description here

CuriousKid
  • 605
  • 5
  • 24
0

Go into the expression builder in the cell you want the subtotal. This will give you a sum based upon a group.

=Sum(Fields!OrderQty.Value, "InsertTheNameOfYourGroup")

If you don't put the Group Scope in the formula, sometimes SSRS will think you want the subtotal of everything.

EDIT:

Sounds like you are looking for a subtotal for each Order. I would suggest creating another child group "SalesOrderNumber"

EDIT2:

If you would like the Subtotal to appear after the last order, go to the visibility/hidden expression for the row that contains the subtotal and use something along the lines...

=IIF(CountRows("InsertYourGroup") = RowNumber(InsertYourGroup), False, True)
Pants
  • 669
  • 7
  • 24
  • No, that's not what I want. What I want is what's in the update, except I only want it to show the last subtotal row. The 79 is correct. There are 79 items total in the orders for product 130. I want that 79 to appear after the last order in the list, not after each order. – Pete Jul 31 '17 at 17:19
  • It looks like grouping issue. The sum expression is grouped with the SO information. – Pradeep Muttikulangara Vasu Jul 31 '17 at 17:38
  • @Pete See my 2nd Edit – Pants Jul 31 '17 at 19:02
0

The problem is that you have both rows in the order number group. This causes the second row to be repeated and also causes the sum to be at the order level.

You want your groups to be staggered like this: enter image description here

To do this, right-click on the Order Number and Insert a row "Outside Group - Below". With this design, the Sum is a subtotal that will only repeat once per Product Code.

StevenWhite
  • 5,907
  • 3
  • 21
  • 46
  • As I said in the original post, if I do the total outside the group, it gives me the total for all products. See Update 2 above. – Pete Jul 31 '17 at 18:08
  • To clarify, the outer group should be grouped by ProductCode and the inner group should be grouped by OrderNumber. You do not need to specify a scope override for the `Sum` function. The key is that the subtotal is inside one group, but outside the other. In update 2 you removed the product group which is why it was for all products. – StevenWhite Jul 31 '17 at 18:22
  • If I don't remove the ProductCode group, it gives me the sum on every other line, as shown in the first update. – Pete Jul 31 '17 at 18:38
  • See Update 3 as well. Maybe that's what you were thinking of? – Pete Jul 31 '17 at 18:58