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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anon29
Helper II
Helper II

Sum only distinct min per category

Hi all, I am wanting to sum the minimum in each ID per month.

If there are duplicate minimum values in the same ID , I want to ignore all other duplicate minimum values except the most recent minimum value. 
Here's what my data looks like and what I want to see below.

 

Anon29_1-1675914664077.png

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anon29 , Add a month year column and measures like

 

 

Last Qty = Var _max = Minx(filter( ALLSELECTED(Data1), Data1[ID] = max(Data1[ID]) && Data1[Month] = max(Data1[Month]) ),Data1[Value])
return
CALCULATE(sum(Data1[qty]), filter( (Data1), Data1[ID] = max(Data1[ID]) && Data1[Value] =_max))

Sum Last Qty = sumx(Summarize(Data1, Data1[ID], Data1[Month Year]) , [Last Qty])

 

 

 

Month year column =  format([Date], "YYYYMM")

 

Latest
https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee8...

View solution in original post

Ahmedx
Super User
Super User

Need to create two calculated columns:
Month = MONTH([Date])

Rx = RANKX(FILTER('Table',[ID]=EARLIER('Table'[ID])&&'Table'[Month]=EARLIER('Table'[Month])),[Date],,ASC)


Also two measures
Count = CALCULATE(COUNTROWS(),'Table'[Month]=MAX('Table'[Month]),REMOVEFILTERS('Table'[Date]))

Result = Var _CurrentCount =[Count]
RETURN
CALCULATE(SUM('Table'[Value]),'Table'[Rx]= max(1,_CurrentCount))

Sample PBIX file attached
https://dropmefiles.com/Kdo3y

Screen Capture #283.png

View solution in original post

3 REPLIES 3
Ahmedx
Super User
Super User

Need to create two calculated columns:
Month = MONTH([Date])

Rx = RANKX(FILTER('Table',[ID]=EARLIER('Table'[ID])&&'Table'[Month]=EARLIER('Table'[Month])),[Date],,ASC)


Also two measures
Count = CALCULATE(COUNTROWS(),'Table'[Month]=MAX('Table'[Month]),REMOVEFILTERS('Table'[Date]))

Result = Var _CurrentCount =[Count]
RETURN
CALCULATE(SUM('Table'[Value]),'Table'[Rx]= max(1,_CurrentCount))

Sample PBIX file attached
https://dropmefiles.com/Kdo3y

Screen Capture #283.png

Anon29
Helper II
Helper II

Hi @amitchandak , It looks like it is summing all the minimum duplicate numbers per ID. I want to record only 1 of the minimum per month for each category and then sum by that. So for ID A in Jan, there are two minimum values of "2", I only want to record this as being just one "2" and disregard the other one. 

This is what came up 

Anon29_0-1675918118898.png

But I was wanting it to show this

Anon29_2-1675918324575.png

 

 

amitchandak
Super User
Super User

@Anon29 , Add a month year column and measures like

 

 

Last Qty = Var _max = Minx(filter( ALLSELECTED(Data1), Data1[ID] = max(Data1[ID]) && Data1[Month] = max(Data1[Month]) ),Data1[Value])
return
CALCULATE(sum(Data1[qty]), filter( (Data1), Data1[ID] = max(Data1[ID]) && Data1[Value] =_max))

Sum Last Qty = sumx(Summarize(Data1, Data1[ID], Data1[Month Year]) , [Last Qty])

 

 

 

Month year column =  format([Date], "YYYYMM")

 

Latest
https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee8...

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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