Forum Discussion
summing values for last date by group
- 9 years ago
A couple of options:
= CALCULATE ( SUM ( Transactions[Quantity] ), GENERATE ( VALUES ( Transactions[Product Category] ), LASTDATE ( Transactions[Date] ) ) )= SUMX ( VALUES ( Transactions[Product Category] ), CALCULATE ( SUM ( Transactions[Quantity] ), LASTDATE ( Transactions[Date] ) ) )
Peter,
That DAX looks OK to me - if you have a visual like a table or graph with "Product Category" and "Last Quantity", won't it give you what you want?
I notice you say "...should result in two rows returned" - are you looking to get a calculated table back rather than a value?
Inherantly the problem is that my DAX formula works if I slice by a single product but if all products are selected then it takes the MAX date across all products and returns the sum of quantities for that. What it should do is get the maximum date for the selected period and product and then sum these.
Ankitpatira I tried out your example thankyou. The problem is though that the user may want to look at this by month, week or Year. So if they pick by month then I need the total quantity summed by product for all those transactions on the last transaction date of each monh.
- OwenAuger9 years agoSuper User
A couple of options:
= CALCULATE ( SUM ( Transactions[Quantity] ), GENERATE ( VALUES ( Transactions[Product Category] ), LASTDATE ( Transactions[Date] ) ) )= SUMX ( VALUES ( Transactions[Product Category] ), CALCULATE ( SUM ( Transactions[Quantity] ), LASTDATE ( Transactions[Date] ) ) )- petercummins9 years agoFrequent Visitor
Owen you sir have made my day!
Perfect simple solution, tested them both thanks!