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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
scaballerom
Helper I
Helper I

Filter on RANKX not working

Hi,


I have the following ranking:

RankStartingTimeDeviation =
IF (
    HASONEVALUE('Fact Jobs'[job_name]) && [NumberOfExec]=1,
VAR LookupTable =
    ADDCOLUMNS(ALLSELECTED('Fact Jobs'),"@Deviation",[StartingTimeDeviation])
VAR CurrentValue = CALCULATE([StartingTimeDeviation], 'Fact Jobs'[job_key] = SELECTEDVALUE('Fact Jobs'[job_key]))
VAR Result =
    RANKX (LookupTable, [@Deviation], CurrentValue,DESC,Dense)
RETURN
    Result
    )
where:
StartingTimeDeviation =
VAR StartTime = SELECTEDVALUE('Fact Jobs'[job_starting_time])
Var AvgStartTime = TIMEVALUE([AvgStartingTimeR6M])
VAR Result = IF (AvgStartTime> StartTime, -DATEDIFF(StartTime,AvgStartTime,MINUTE), DATEDIFF(AvgStartTime,StartTime,MINUTE))
RETURN
    Result
and
AvgStartingTimeR6M =
VAR NumberOfDays = 181
VAR MaxDay = MAX('Fact Jobs'[job_starting_datetime])
VAR MinDay = MaxDay-NumberOfDays
VAR FilterContext =
    FILTER (
            ALL('Fact Jobs'),
            'Fact Jobs'[job_status]="Completed" &&
            'Fact Jobs'[job_key] = SELECTEDVALUE('Fact Jobs'[job_key]) &&
            'Fact Jobs'[job_starting_datetime] <= MaxDay && 'Fact Jobs'[job_starting_datetime] > MinDay)
VAR Result =
    CALCULATE(FORMAT(AVERAGE('Fact Jobs'[job_starting_time]),"HH:mm:ss"),FilterContext)
RETURN
    Result
and 
NumberOfExec = CALCULATE(COUNT('Fact Jobs'[job_key]),REMOVEFILTERS('Fact Jobs'[job_starting_time]), KEEPFILTERS('Fact Jobs'[job_starting_date]))
 
The problem I have is that when I try to filter on RankStartingTimeDeviation, all my rows turn blank.

Could someone help me out?
 
Thanks in advance for your help!

BR,
Sara
1 REPLY 1
v-zhangti
Community Support
Community Support

Hi, @scaballerom 

 

Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures. I look forward to your response.

 

Best Regards,

Community Support Team _Charlotte

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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