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
deskow80
Frequent Visitor

RANKX By Grouping for a given date period

I have three tables:

DateDimension

Employee

Settlement

 

The Employee table has a column labeled TrainingClass

 

I am trying to create a rank that will update dynamically based on the date range selected by BilledContributions from the Settlement table.

 

I have a measure called TotalBilledContributions:

 

TotalBilledContributions =
VAR _StartDate = MIN(DateDimension[Date])
VAR _EndDate = MAX(DateDimension[Date])
RETURN
SUMX(
    FILTER(Settlement,Settlement[BatchDate] >= _StartDate && Settlement[BatchDate] <= _EndDate),
    Settlement[BilledContributions]
)

 

And I have a calculated column called RankbyTrainingClass:

 

RankbyTrainingClass =
VAR _StartDate = MIN(DateDimension[Date])
VAR _EndDate = MAX(DateDimension[Date])
RETURN
RANKX(
    FILTER(
        ALL(Employee),
        Employee[TrainingClass] = EARLIER(Employee[TrainingClass])
    ),
    CALCULATE([TotalBilledContributions],Settlement[BatchDate] >= _StartDate && Settlement[BatchDate] <= _EndDate),
    ,
    DESC,
    Dense
)
Link to .pbix file in Google Drive: PBIX file 
I was expecting the rank to be based on the TotalBilledContributions measure decending, but I'm not getting that as a result. Any help is greatly appreciated. I'm getting unexpected results as follows: 
EmployeeNameTotalBilledContributionsRankbyTrainingClass
Ryan K1,581.69

1

Brandon S109.52

2

Lionel R397.60

3

Will C30.60

4

Nathan H30.06

5

1 REPLY 1
deskow80
Frequent Visitor

I changed the ranking to a measure instead of a calculated column and modified the DAX to:

Rank =
VAR _StartDate = MIN(DateDimension[Date])
VAR _EndDate = MAX(DateDimension[Date])
RETURN
CALCULATE(
    RANKX(
        FILTER(
            ALL(Employee),
            Employee[TrainingClass] = SELECTEDVALUE(Employee[TrainingClass])
        ),
        CALCULATE([TotalBilledContributions],Settlement[BatchDate] >= _StartDate && Settlement[BatchDate] <= _EndDate),
        ,
        DESC,
        Dense
    ),
    ALLSELECTED(Employee[TrainingClass])
)
 
This appears to be working as desired. If you see any issues, let me know.

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.