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
Anonymous
Not applicable

Calculate with filter expressions

Hello,

I have following measure which doesn't work when i am using variable varRank2 as a condition with CurrentVal. 

Ratio Kms For Rank2 To Actual = 
VAR varRank2 = 'FPOC Main'[Rank 2 Kms By Month]

VAR TotalActual =    
    CALCULATE(
        MAX('FPOC Main'[ActualSumFromViewSummary]),
        'FPOC Main'[FPOC_Date] = SELECTEDVALUE(DimDate[DateInDateFormat])
    )

VAR CurrentVal = 
    CALCULATE(
        SUM('FPOC Main'[kms]),
        FILTER(
            'FPOC Main',
            'FPOC Main'[Measurement_End_Code] = varRank2
        )
    )
VAR Ratio = 
DIVIDE(
    CurrentVal,
    TotalActual,
    0
)
RETURN 
CurrentVal

 varRank2 returns text value which should filter 'FPOC Main' table to second Measure_End_Code name based on calculated percentage.
Measure Rank 2 Kms By Month is calculated as follows:

Rank 2 Kms By Month = 
CALCULATE(
    MAX('FPOC Main'[Measurement_End_Code]),
    FILTER(
        VALUES('FPOC Main'[Measurement_End_Code]),
        RANKX(
            ALL('FPOC Main'[Measurement_End_Code]), 
            CALCULATE('FPOC Main'[% Kms By Month]))=2
    )
)

and when i put that value in card visual it shows correct value. Further more, there are also Rank1 measures build in the same way and those seems to work, so filter expression in CurrentVal works. 

One more thing, when i put literal value instead of a variable value it works.
Can't figure it out, no idea what is going on.

Any help?

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , I think you should try new Index function , that can help

Power BI Index function: Top/Bottom Performer by name and value- https://youtu.be/HPhzzCwe10U

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

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.