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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

RANKX on Date Excluding Filter Context

Hi,

 

I am trying to create a little bit of a nuanced RANKX function.

 

Here's the dataset.

kewaynes33_0-1649449395918.png

What I need to do is create a RANKX function that ranks the dates in descending order for each job. But it needs to take into account the Project Number context. So ultimately, it will look like this:

 

kewaynes33_1-1649449495880.png

 

Any help is much appreciated!

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @Anonymous ,

 

How about this:

tomfox_0-1649602102176.png

 

 

Here the measure:

MeasureCount = 
VAR _helpTable = 
SUMMARIZE ( 
    Table, 
    [Project #],
    "maxDate", CALCULATE ( MAX ( Table[Date] ) )
)
RETURN
SUMX ( Table, CALCULATE ( MAX ( Table[Count] ) , FILTER (_helpTable, Table[Date] = [maxDate] )))

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

10 REPLIES 10
tackytechtom
Super User
Super User

Hi @Anonymous ,

 

How about this:

tomfox_0-1649602102176.png

 

 

Here the measure:

MeasureCount = 
VAR _helpTable = 
SUMMARIZE ( 
    Table, 
    [Project #],
    "maxDate", CALCULATE ( MAX ( Table[Date] ) )
)
RETURN
SUMX ( Table, CALCULATE ( MAX ( Table[Count] ) , FILTER (_helpTable, Table[Date] = [maxDate] )))

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

Thanks Tom!

tackytechtom
Super User
Super User

Hi @Anonymous ,

 

Another way to solve it is in Power Query:

tomfox_1-1649454048894.png

 

1) Sort Descending on date 

tomfox_2-1649454108611.png

 

2) Group by Project #

tomfox_3-1649454150919.png

 

3) Create a custom column (index):

tomfox_4-1649454188658.png

 

Here the code:

Table.AddIndexColumn([Projects], "index", 1 )

 

4) Expand the Custom column:

tomfox_5-1649454263497.png

 

5) rename and hide the columns you do not need anymore

 

I think I read somewhere that it is better to create indexes / ranks in Power Query than in DAX, if possible. So this might be the prefered solution compared to the previous solution I posted.

 

Does this help? 🙂

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @Anonymous ,

 

Here a solution in DAX:

tomfox_0-1649453508149.png

 

Here the code:

Rank = 
RANKX ( 
    FILTER ( 
        Table1, 
        Table1[Project #] = EARLIER ( Table1[Project #] )
    ),
    Table1[Date],
    , DESC
    , DENSE
)

 

Does this help? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

Tried recreating but I'm getting this error.

kewaynes33_0-1649454326740.png

 

Hi @Anonymous ,

 

It seems like you were trying to create a measure instead of a calculated column. Can you try it with a calculated column and let me know if it works? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

I've got this so far.

 

kewaynes33_0-1649459662295.png

 

It just still doesn't dynamically change when I filter down to only the Job #1s.

kewaynes33_1-1649459699853.png

 

I imagine I need to use some kind of ALLSELECTED somewhere. I just can't figure out where and on exactly what column...

 

Anonymous
Not applicable

You're right 😉. And something I should have mentioned in the original post is that I'm needing it to be dynamic, so I'm guess that a CC won't work. If I filter down to just job one, then I would want each of these to now reflect rank of 1, instead of their original rank.

kewaynes33_0-1649455320071.png

 

Really, what I am trying to do is be able to return the Count value by Project based on the the job that has the max date within the current filter context.

 

So, if there is no filter applied, the count for Project 1 would be 50 and Project 2 would be 20.

kewaynes33_1-1649455459609.png

 

However, if I were to filter down to only Job #1s, then the count for Project 1 would be 5 and for Project 2 would be 15.

 

kewaynes33_2-1649455519567.png

 

 

My thought was that if I could get a dynamic ranking measure, I could then filter to whatever is ranked as 1 (the max date for the project within the current filter context).

 

Hopefully my tangent makes halfway sense...

 

Hi @Anonymous ,

 

Is it this you are looking for? 🙂

tomfox_0-1649494110028.png

tomfox_1-1649494128692.png

 

tomfox_2-1649494144520.png

 

tomfox_3-1649494156993.png

 

Here would be the measure:

MeasureCount = 
VAR _maxDate = CALCULATE ( MAX ( 'Table'[Date] ) )
RETURN
CALCULATE ( MAX ( Table[Count] ),  'Table'[Date] = _maxDate )

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

I think that's getting close. I think I would need these to be blank.

kewaynes33_8-1649514878801.png

 

Because ultimately what I need is a card that just returns the sum of the counts based on the newest job for each project. So if nothing is filtered, it would be 70.

kewaynes33_9-1649514967492.png

 

And if it's filtered to job 1, it would be 20

kewaynes33_10-1649515008081.png

I would then need to throw this into a column chart as well that's filtered by the category.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.