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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Live connection - create measure with max value and second max value of column

Hello everyone,

 

I have the following measure in Live connection in Power BI desktop:

Variation = 
VAR Code_T = 1600
VAR Code_T_1 = 1500
VAR SUM_T = CALCULATE([Measure1];Table[Code_Column] = Code_T)
VAR SUM_T_1= CALCULATE([Measure2];Table[Code_Column] = Code_T_1)
return SUM_T - SUM_T_1

 

 

Code_T and Code_T-1 are the max and second max respectively of Code_Column, for each of these I calculate the [Measure1] and [Measure2] that already exists in the model.

 

If I hardcode the values 1600 and 1500 this works really well.

 

But instead of hardcoding the values I would like them to be dynamic so I would like to put the max value of Code_Column in Code_T, instead of 1600, and put the second max value of Code_Column in Code_T_1, instead of 1500.

 

I tried the following but with no success:

 

Variation = 
VAR Code_T = MAX(Code_Column)
VAR Code_T_1 = CALCULATE(MAX(Table[Code_Column]);Table[Code_Column] < Code_T)

VAR SUM_T = CALCULATE([Measure1];Table[Code_Column] = Code_T)
VAR SUM_T_1= CALCULATE([Measure2];Table[Code_Column] = Code_T_1)

return SUM_T - SUM_T_1

 

 

Any ideas? I'm kind of new to DAX.

 

Thank you.

 

1 REPLY 1
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Can we have a data sample?

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.