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

Sum when version is highest by another variable (no max version in the whole data)

Hi, I'm struggling having this measure to work.

I would like to have a measure that will sum the Value only for the max version for each house.

 

So following this example table:

 

House_IdVersion_IdValue
111000
122000
213000
315000

 

The result of this measure should be: 10.000 because the house_id 1 version 1 is ignored as there's another version higher.

By House_id the result should be:

 

House_IdValue
12000
23000
35000

 

Can anyone help me?

 

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

The only answer that works, and even with other columns (like Color_id, or more) is this one answered in SO:

 

https://stackoverflow.com/questions/61390142/sum-where-version-is-highest-by-another-variable-no-max...

View solution in original post

21 REPLIES 21
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous , can you try it? Replace the Table1 with your own table name.

 

Measure =
VAR T1 = GROUPBY(Table1,Table1[House_Id],"MaxV",MAXX(CURRENTGROUP(),[Version_Id]))
RETURN
CALCULATE(SUM('Table1'[Value]),TREATAS(T1,'Table1'[House_Id],Table1[Version_Id]))
HotChilli
Super User
Super User

Something like this measure:

MSum = VAR _maxVer = CALCULATE(MAX(TableR[Version_Id]), ALLEXCEPT(TableR, TableR[House_Id]))
RETURN
    CALCULATE(SUM(TableR[Value]), TableR[Version_Id] = _maxVer)

Please test with a larger sample dataset

Anonymous
Not applicable

No,

 

This would return just 2000

@Anonymous , Create a measure like this and ad

Measure =
VAR __id = MAX ( 'Table'[House_Id] )
VAR __Version_Id = CALCULATE ( MAX( 'Table'[Version_Id] ), ALLSELECTED ( 'Table' ), 'Table'[House_Id] = __id )
RETURN CALCULATE ( sum ( 'Table'[Value] ), VALUES ( 'Table'[House_Id ), 'Table'[House_Id] = __id, 'Table'[Version_Id] = __Version_Id )

Anonymous
Not applicable

@amitchandak That didn't work

@Vera_33 That also didn't work

Hi @Anonymous ,

 

Try this measure:

 

MaxValue =
SUMX(ADDCOLUMNS(SUMMARIZE('Table'; 'Table'[House_Id]; "MaxValue"; MAX('Table'[Version_Id])); "Value";
CALCULATE(SUM('Table'[Value]); FILTER(ALL('Table'); 'Table'[House_Id] = EARLIER('Table'[House_Id]) && 'Table'[Version_Id] = [MaxValue]))); [Value])
 
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

Didn't work @camargos88 

@Anonymous this will do it

 

Measure = 
SUMX ( 
    VALUES ( 'Table'[House_Id] ), 
    CALCULATE ( 
        MAX ( 'Table'[Value] ), 
        ALLEXCEPT ( 'Table', 'Table'[House_Id] ) 
    )
)

 

I would 💖 Kudos 🙂 if my solution helped. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k nope, this measure does not even take into account eht Version_Id

@Anonymous ah, I missed that, I thought you want the highest value of the house ignoring version, but I think you are looking the value of the highest version of the house. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@Anonymous here it is, add the following two measures and measure 2  will do the job

 

Measure = 
CALCULATE ( 
    SUM ( 'Table'[Value] ),
    FILTER ( 
        ALLEXCEPT ( 'Table', 'Table'[House_Id] ), 
        'Table'[Version_Id] = MAX ( 'Table'[Version_Id]  )
    )
)


Measure 2 = SUMX ( VALUES ( 'Table'[House_Id] ), [Measure] )

 

I would 💖Kudos 🙂 if my solution helped. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k  This doesn't work also. The think is that the measure should Summarize by House_Id on the Max(Version_Id), then do an INNER JOIN with the main table. Then sum on this virtual table.

 

But I don't know how to do this with dax.

@Anonymous It Seems like I'm not seeing all the details. See the attached solution and it works, you can take it from there or provide what I'm missing.

 

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

ok @parry2k It works on your version, but in reallity I have more variables, such as Color_Id and more.

 

Therefore If I want to sum by color_Id insted of House_Id It does not work.

 

See https://we.tl/t-GaIKGSNEDP 

@Anonymous so you by the colour id of the same house or colour id across all the houses?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Color Id accross all house but only taking into account where version is max on each house.

Hey, you never mentioned you have color id. You need to modify the measure accordingly. I got it in your shared file.

 

Measure 3 =
VAR T1= GROUPBY('Table','Table'[House_Id],'Table'[Color_Id],"MaxV",MAXX(CURRENTGROUP(),[Version_Id]))
RETURN
CALCULATE(SUM('Table'[Value]),TREATAS(T1,'Table'[House_Id],'Table'[Color_Id],'Table'[Version_Id]))

 
 
Anonymous
Not applicable

The only answer that works, and even with other columns (like Color_id, or more) is this one answered in SO:

 

https://stackoverflow.com/questions/61390142/sum-where-version-is-highest-by-another-variable-no-max...

@Anonymous so what makes you think it is not working by color, I think it is correct until I'm missing something, can you tell me the expected output by color.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k That's correct I want to sum the values for all the houses but only where the version id is the max on each house.

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.