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
cfstout
Regular Visitor

Help with Measure using RANKX and TOPN

Hi, I have a table that provides the TOP 5 Property names by using slicers for StartDate and Plan.  The table aggregates the count of Sessions and provides a Total.  This would be Total Sessions for Top 5 properties based on filter of Plan and filter of Date.

 

I am needing to create a measure that would provide that same number. 

Example:  Slicers for Plan2 and 03/01/2022.  The has the Top N filter for Top 5 by Session Ct.  The Total = 39.  The measure would provide that same Total.

I believe this is needing RANKX and TOPN, but cannot figure out how to write it.

Sample Data

 

Session IDUser IDPlanProperty NameStartDateStation ID
2624657186585Plan1Property 1633/1/2022700082-09
2624661176331Plan4Property 2413/1/2022100275-05
2624668118275Plan1Property 713/1/2022210186-04
2624813130501Plan1Property 1383/1/2022100054-03
2624823280591Plan3Property 4903/1/2022200220-02
2624848198035Plan1Property 2043/1/2022100200-02
2624862279846Plan1Property 4613/1/2022100178-04
2624911203896Plan1Property 203/1/2022200101-02
2624913178997Plan1Property 4433/1/2022100600-03
2624928164836Plan1Property 4023/1/2022100268-02
2624930163930Plan1Property 1633/1/2022700082-09
2624937251280Plan1Property 343/1/2022200050-02
2624940267771Plan1Property 3283/1/2022600138-05
2624942142759Plan4Property 3253/1/2022200049-03
2624952119232Plan4Property 2853/1/2022210077-01
2624956257189Plan3Property 1833/1/2022100020-03
2624959272405Plan3Property 3873/1/2022100042-04
2624966163060Plan1Property 4743/1/2022100189-02
2624971267825Plan3Property 3483/1/2022100219-02
2624972278954Plan3Property 1833/1/2022100252-04

 

This is a sample data set.  The data set I am working with has over 100k lines, each session id is unique.  All other columns will have duplications.

Any suggestions?  Thanks in advance for any help provided.

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @cfstout,

 

You may try this solution.

Here are the sample data used.

vcazhengmsft_0-1651563311343.png

 

Create a Measure like this.

TotalSessionsForTop5Properties =
VAR Top5_Properties =
    TOPN (
        5,
        SUMMARIZE (
            'Table',
            'Table'[Property Name],
            "Num",
                CALCULATE (
                    COUNT ( 'Table'[Session ID] ),
                    FILTER (
                        ALLEXCEPT('Table','Table'[Property Name]),
                        'Table'[Plan] = SELECTEDVALUE ( 'Table'[Plan] )
                            && 'Table'[StartDate] = SELECTEDVALUE ( 'Table'[StartDate] )
                    )
                )
        ),
        [Num], DESC
    )
RETURN
    SUMX ( Top5_Properties, [Num] )

 

Then, the result looks like this.

vcazhengmsft_1-1651563311346.png

 

Also, attach the pbix file as reference. Hope it helps.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

View solution in original post

1 REPLY 1
v-cazheng-msft
Community Support
Community Support

Hi @cfstout,

 

You may try this solution.

Here are the sample data used.

vcazhengmsft_0-1651563311343.png

 

Create a Measure like this.

TotalSessionsForTop5Properties =
VAR Top5_Properties =
    TOPN (
        5,
        SUMMARIZE (
            'Table',
            'Table'[Property Name],
            "Num",
                CALCULATE (
                    COUNT ( 'Table'[Session ID] ),
                    FILTER (
                        ALLEXCEPT('Table','Table'[Property Name]),
                        'Table'[Plan] = SELECTEDVALUE ( 'Table'[Plan] )
                            && 'Table'[StartDate] = SELECTEDVALUE ( 'Table'[StartDate] )
                    )
                )
        ),
        [Num], DESC
    )
RETURN
    SUMX ( Top5_Properties, [Num] )

 

Then, the result looks like this.

vcazhengmsft_1-1651563311346.png

 

Also, attach the pbix file as reference. Hope it helps.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

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.

Top Solution Authors