cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BI_Pro
Frequent Visitor

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

Accepted Solutions
Super User II
Super User II

Re: Summation by category with Max calculated after Applicable of Slicers

@BI_Pro  - 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
Super User III
Super User III

Re: Summation by category with Max calculated after Applicable of Slicers

@BI_Pro 

 

Try this MEASURE

 

Measure = CALCULATE(SUM(Table1[Sales]),LASTDATE(Table1[Sale Date]))
Try my new Power BI game Cross the River
BI_Pro
Frequent Visitor

Re: Summation by category with Max calculated after Applicable of Slicers

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

Highlighted
Super User IV
Super User IV

Re: Summation by category with Max calculated after Applicable of Slicers

Hi,

Zubair's formula works just fine.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
BI_Pro
Frequent Visitor

Re: Summation by category with Max calculated after Applicable of Slicers

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. 

 

Super User II
Super User II

Re: Summation by category with Max calculated after Applicable of Slicers

@BI_Pro  - 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

BI_Pro
Frequent Visitor

Re: Summation by category with Max calculated after Applicable of Slicers

Thank you so much it worked.

Helpful resources

Announcements
‘Better Together’ T-Shirt Contest – Winner Announced!

‘Better Together’ T-Shirt Contest – Winner Announced!

And the winner is...

Announcing the New Spanish Forum

Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

Attending MBAS? Claim your badge

Attending MBAS? Claim your badge

Whether you’re streaming the digital event live, or watching on-demand, claim your attendee badge to sport on your profile.

April 2020 Community Highlights

April 2020 Community Highlights

Info on our Super Users, MBAS content and badges, and updates to our support articles. - Read the full Community Highlights.

MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Top Solution Authors
Top Kudoed Authors