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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
dknipfer
New Member

Use RANK(X) to Filter Values

I need a way to figure out how many sites were online given a specific time. I need to include the ability to slice to a different timeframe. I am using RANK to create a measure and determine the latest row to be counted (Grouped by Site, ordered DESC by ReadEffective then DESC RecordedDateTime). I need to Countrows filtering to Status = 1 AND Rank = 1, or another method of counting active Sites. Also needed is the ability to slice the dates. When I set the latest range of the table to 08/28/2024, for example, the Rank would update to show Sites A, B and D as active as of the last ReadEffective dates, 08/16/2024 (A & B) and 8/25/2024 (D). I cannot filter the Card visual using RANK because it is a measure. How do I accomplish this?

 

SiteStatusReadEffectiveRecordedDateTimeRANK (measure)
A08/30/20248/31/24 12:00 AM1
A18/30/20248/31/24 10:00 AM2
A18/16/20248/17/24 10:00 AM3
A18/2/20248/3/24 10:00 AM4
A17/19/20247/20/24 10:00 AM5
B18/29/20248/31/24 12:00 AM1
B18/16/20248/18/24 12:00 AM2
B18/3/20248/5/24 12:00 AM3
B17/21/20247/23/24 12:00 AM4
C18/25/20248/25/24 12:00 AM1
C08/12/20248/12/24 12:00 AM2
C17/29/20247/30/24 12:00 AM3
C17/28/20247/17/24 12:00 AM4
C17/27/20247/4/24 12:00 AM5
C17/26/20246/21/24 12:00 AM6
D18/30/20248/30/24 12:00 AM1
D18/25/20248/30/24 12:00 AM2
D18/20/20248/30/24 12:00 AM3
1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @dknipfer 

One initial question: If you set the latest range to 08/28/2024, would C not also be active, since it is active as of its latest ReadEffectiveDate 08/25/2024?

 

Putting that to one side, I would recommend this general approach:

1. Set up the model with 'Date' table related to ReadEffective.

Use 'Date' table for all date filtering.

OwenAuger_0-1727417184309.png

2. Create these measures, using INDEX to identify the "latest" rows

Latest Active Site Count returns the number of Sites that are active as at their "latest" row up to and including the max filtered date.

 

Active Site Count = 
VAR LatestRows =
    INDEX (
        1,
        SUMMARIZE ( Data, Data[Site], Data[ReadEffective], Data[RecordedDateTime], Data[Status] ),
        ORDERBY ( Data[ReadEffective], DESC, Data[RecordedDateTime], DESC ),
        DEFAULT,
        PARTITIONBY ( Data[Site] )
    )
VAR LatestRowsActive =
    FILTER ( LatestRows, Data[Status] = 1 )
VAR Result = CALCULATE ( DISTINCTCOUNT ( Data[Site] ), LatestRowsActive )
RETURN
    Result
Latest Active Site Count = 
// Active Site Count up to and including the max filtered Date.
CALCULATE (
    [Active Site Count],
    'Date'[Date] <= MAX ( 'Date'[Date] )
)

 

 

3. Use Latest Active Site Count in visuals:

OwenAuger_0-1727417424819.png

Have I captured the logic correctly, and does this work in your actual model?

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

4 REPLIES 4
dknipfer
New Member

This worked like a charm! If I run into any issues I may be back, but right now it's doing exactly what I need.

 

And to your question, yes, C would still be active. I had been trying to show Sites that would change status or EffectiveDates from the original filter. Sorry for the confusion.

OwenAuger
Super User
Super User

Hi @dknipfer 

One initial question: If you set the latest range to 08/28/2024, would C not also be active, since it is active as of its latest ReadEffectiveDate 08/25/2024?

 

Putting that to one side, I would recommend this general approach:

1. Set up the model with 'Date' table related to ReadEffective.

Use 'Date' table for all date filtering.

OwenAuger_0-1727417184309.png

2. Create these measures, using INDEX to identify the "latest" rows

Latest Active Site Count returns the number of Sites that are active as at their "latest" row up to and including the max filtered date.

 

Active Site Count = 
VAR LatestRows =
    INDEX (
        1,
        SUMMARIZE ( Data, Data[Site], Data[ReadEffective], Data[RecordedDateTime], Data[Status] ),
        ORDERBY ( Data[ReadEffective], DESC, Data[RecordedDateTime], DESC ),
        DEFAULT,
        PARTITIONBY ( Data[Site] )
    )
VAR LatestRowsActive =
    FILTER ( LatestRows, Data[Status] = 1 )
VAR Result = CALCULATE ( DISTINCTCOUNT ( Data[Site] ), LatestRowsActive )
RETURN
    Result
Latest Active Site Count = 
// Active Site Count up to and including the max filtered Date.
CALCULATE (
    [Active Site Count],
    'Date'[Date] <= MAX ( 'Date'[Date] )
)

 

 

3. Use Latest Active Site Count in visuals:

OwenAuger_0-1727417424819.png

Have I captured the logic correctly, and does this work in your actual model?

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

If I were to add another column of detail to this, say Region, how would I change these measures to perform the same task? I'd be looking to create a bar chart and allow for clicking and filtering of the data by Region.

@dknipfer 

If you are grouping/filtering by Region, the measures shouldn't need to change.

The measures would return the latest active site count within a particular region.

Could you post back an example of how you would want the calculation to work in this case? 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

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.