Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Summation by category with Max calculated after Applicable of Slicers

This questions may have been answered but after scouring for hours over the forum i could not find a solutuion that works . DAX Gurus please help. 

I need to get the Latest Sale data grouped by category where the year column is a slicer

Here is the data set 

CategoryYearItemSale DateSales
A2018A1Jan-1810
A2018A1Feb-1820
A2018A2Jan-1830
A2018A2Feb-1840
A2019A1Jan-1912
A2019A1Feb-1922
A2019A2Jan-1932
A2019A2Feb-1942
B2018B1Jan-18100
B2018B1Feb-18200
B2018B2Jan-18300
B2018B2Feb-18400
B2019B1Jan-19110
B2019B1Feb-19120
B2019B2Jan-19130
B2019B2Feb-19140

 

If user selects 2018 in the year slicer . The resulting rows should be the sum of Sales for latest record for each item from 2018  grouped by the Category. Result would be  

(i.e sum of A1 Feb 2018 sales + A2 Feb 2018 Sales grouped by category A  and Similarly for B) 

 

CategorySales
A60
B600

 

if user selected 2019 

Result would be  sum of A1 Feb 2019 sales (22) + A2 Feb 2019 Sales(42)  grouped by category A   (and similarly for B) 

CategorySales
A64
B260

 

If user selects 2018 and 2019, only the latest records (2019) should be picked up . Result would be 

(i.e sum of A1 Feb 2019 sales + A2 Feb 2019 Sales grouped by category A  and Similarly for B) 

CategorySales
A64
B260

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous  - Try this Measure:

 

Last Sales = 
CALCULATE(
    SUM(mytable[Sales]),
    TREATAS (
        SUMMARIZE(mytable, mytable[Category],mytable[Item],"Sale Date",MAX(mytable[Sale Date])),
        mytable[Category],
        mytable[Item],
        mytable[Sale Date]
    )
)

The filter limits to only those columns which match the Category, Item, and Max Sales Date.

TREATAS is necessary to avoid the other columns creeping back in. Refer to this site to better understand it.

 

Cheers!

Nathan

View solution in original post

6 REPLIES 6
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Try this MEASURE

 

Measure = CALCULATE(SUM(Table1[Sales]),LASTDATE(Table1[Sale Date]))

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

The last Date can vary by item during each year. And i'm not including item in the final display. 

Hi,

Zubair's formula works just fine.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

It didnt work for me. Let me elaborate. There can be an item A3 with only record in Jan 2019 . When user selects jan 2018 It should pick up 

A1- from Feb 2019 

A2 from Feb 2019 

A3 from Jan 2019 and sum up the data by category. 

 

Anonymous
Not applicable

Thank you so much it worked.

Anonymous
Not applicable

@Anonymous  - Try this Measure:

 

Last Sales = 
CALCULATE(
    SUM(mytable[Sales]),
    TREATAS (
        SUMMARIZE(mytable, mytable[Category],mytable[Item],"Sale Date",MAX(mytable[Sale Date])),
        mytable[Category],
        mytable[Item],
        mytable[Sale Date]
    )
)

The filter limits to only those columns which match the Category, Item, and Max Sales Date.

TREATAS is necessary to avoid the other columns creeping back in. Refer to this site to better understand it.

 

Cheers!

Nathan

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.