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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
NB689
Helper I
Helper I

Dax to show % change from highest value to second highest

Hello I have the below data and I would like to create a card that show the percent change from the highest date value (9/18) to the second highest (9/17). So my intention would to be a value that shows -3.077 %.

 

DateHours Logged In
9/16/20229.5
9/17/20226.5
9/18/20226.3

Hours Logged In is a calculated measure in the table "Non Overlapping" and Date is in the Date Range table with a relationship tied to the other table.

 

Thank you

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @NB689 ,

 

I checked your code and I think you need to use ALL() function in your filter.

Login Change by Day =
VAR _HourofMax =
    SUMX (
        FILTER ( ALL ( 'Date Range' ), 'Date Range'[Date] = [Max Login Date] ),
        [Hours Logged In]
    )
VAR _HourofMin =
    SUMX (
        FILTER ( ALL ( 'Date Range' ), 'Date Range'[Date] = [Min Date] ),
        [Hours Logged In]
    )
RETURN
    DIVIDE ( _HourofMax - _HourofMin, _HourofMin )

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@NB689 ,

Try measure like

Var _max = maxx(allselected(Table), Table[Date])

Var _min = maxx(filter( allselected(Table), Table[Date] <_max), Table[Date] )

return

Divide( calculate( sum(Table[Value]), filter('Table', 'Table'[Date] =_max)) - calculate( sum(Table[Value]), filter('Table', 'Table'[Date] =_min)) ,calculate( sum(Table[Value]), filter('Table', 'Table'[Date] =_min))  )

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I made some more progress by using Sumx instead of Sum since my value is a measure. But my calculation is way off at 45%. Also I split this out into 3 different measures instead of using variables to help me troubleshoot. The max and min login days are working as they should. 

 

NB689_0-1664381775462.png

 

Anonymous
Not applicable

Hi @NB689 ,

 

I checked your code and I think you need to use ALL() function in your filter.

Login Change by Day =
VAR _HourofMax =
    SUMX (
        FILTER ( ALL ( 'Date Range' ), 'Date Range'[Date] = [Max Login Date] ),
        [Hours Logged In]
    )
VAR _HourofMin =
    SUMX (
        FILTER ( ALL ( 'Date Range' ), 'Date Range'[Date] = [Min Date] ),
        [Hours Logged In]
    )
RETURN
    DIVIDE ( _HourofMax - _HourofMin, _HourofMin )

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

That is working great now, thank you! Just trying to build my understanding, how do you know when you need to apply ALL when using a filter? I think this is due to my 'Hours Logged In' being a measure.

I'm not able to pull my value into the return expression. I believe since it is a measure that represents a column. Not sure if I need to add a SELECTED statement for that to work? 

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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