title: Getting a subtotal in an SSRS report
body: <p>I have what ought to be a very simple issue, but I can't seem to solve it.</p>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p><a href="https://i.stack.imgur.com/ivbAF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ivbAF.png" alt="Product Availability"></a></p>
  
  <p>So this is my setup for the first table. The products list and then the row below has the subreport.</p>
  
  <p>The second table is as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/4ofSn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4ofSn.png" alt="Table 2 details"></a></p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>So to handle the filtering, I create the group on ProductCode and then add this filter:</p>
  
  <p><a href="https://i.stack.imgur.com/O2hfJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O2hfJ.png" alt="Product Code Filter"></a></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>If I simply right click on the <code>OrderQty</code> 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.</p>
  
  <p>Alternatively, if I add a row inside the group, after, and add a Sum() for the <code>CaseCount</code>, 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.</p>
  
  <p>This seems like it ought to be ridiculously simple, but I'm stumped.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Chance Finley below suggested Sum(field, groupname), and I tried that. It actually does the sum properly, but it displays it improperly. </p>
  
  <p><a href="https://i.stack.imgur.com/iarlr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iarlr.png" alt="Report with sum of group"></a></p>
  
  <p>Here's what it looks like in Visual Studio...</p>
  
  <p><a href="https://i.stack.imgur.com/t2NM5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t2NM5.png" alt="SSRS Designer Layout"></a></p>
  
  <p><strong>Update 2</strong></p>
  
  <p>If I add the total outside the group, as shown here:</p>
  
  <p><a href="https://i.stack.imgur.com/R1yIu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R1yIu.png" alt="Outside Group"></a></p>
  
  <p>I get the following results:</p>
  
  <p><a href="https://i.stack.imgur.com/pLgCJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pLgCJ.png" alt="Outside group totals"></a></p>
  
  <p>Which puts my sum right where I want it, but it's counting all the products.</p>
  
  <p><strong>Update 3</strong></p>
  
  <p>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:
  <a href="https://i.stack.imgur.com/oHurx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oHurx.png" alt="Between two groups"></a></p>
  
  <p>And here's how it comes out:
  <a href="https://i.stack.imgur.com/VU8lc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VU8lc.png" alt="Between two groups totals"></a>
  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...</p>
  
  <p><strong>Update 4</strong></p>
  
  <p>Following the steps provided by CuriousKid, I got closer...</p>
  
  <p>The setup following his steps (not all fields filled in yet):
  <a href="https://i.stack.imgur.com/fYVKG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fYVKG.png" alt="Almost"></a></p>
  
  <p>And the results:</p>
  
  <p><a href="https://i.stack.imgur.com/0qhhO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0qhhO.png" alt="Almost totals"></a></p>
  
  <p>Problem is that it's all product results shown in details under each product.</p>