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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Filter top 3 rows for each userID in PowerBI

Hi all,   I am new to PowerBI. 

I am trying to get below desired output in 3-steps.

 

Screenshot: 

skondi_0-1592941969055.png

 

T1-Raw data : 

UserIDGroupSpecialty
101a1S-51
101a2S-51
101a3S-51
101a2S-51
101a5S-51
101a1S-51
101a2S-51
201a1S-9
201a3S-9
201a3S-9
201a4S-9
201a5S-9
201a5S-9
201a1S-9
301a1S-15
301a1S-15
301a5S-15

 

Step -1 (T2-count per group per user) : 

Here I can use a measure , but I am making a summary table for understanding purpose.

 

summary = SUMMARIZE(T1-Raw data,SampleData[UserID],T1-Raw data[Specialty],T1-Raw data[Group],"countof",count(T1-Raw data[Group]))

 

Step -2 (T3- Sorted and top-3 rows filtered for each UserID) : 

I am not getting any logic for this ..I tried this simple ranking ,but its not working.

 

Rank = RANKX('T1-Raw data','T1-Raw data'[countof],,ASC,Dense)

 

 Step -3 (T4-Final output using CONCATENATEX) : 

Here I can use CONCATENATEX function to show the the data in single row for each user.

 

So can someone help me for step-2?

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Create 2 measures as below:

 

Measure= CALCULATE(COUNT('Table'[Group]),FILTER('Table','Table'[UserID]=MAX('Table'[UserID])))
T2 = IF(RANKX(FILTER(ALL('Table'),'Table'[UserID]=MAX('Table'[UserID])&&'Table'[Specialty]=MAX('Table'[Specialty])), 
RANKX(FILTER(ALL('Table'),'Table'[UserID]=MAX('Table'[UserID])&&'Table'[Specialty]=MAX('Table'[Specialty])),CALCULATE(COUNTA('Table'[Group])),,DESC,Dense)+
RANKX(FILTER(ALL('Table'),'Table'[UserID]=MAX('Table'[UserID])&&'Table'[Specialty]=MAX('Table'[Specialty])),CALCULATE(MAX('Table'[Group])),,ASC,Dense)
/COUNTROWS(FILTER(ALL('Table'),'Table'[UserID]=MAX('Table'[UserID]))),,ASC,Dense)<=3,'Table'[Measure 2],BLANK())

 

And you will see:

Annotation 2020-06-24 154239.png

And for D1 and D2,see below:

 

_D1 = CONCATENATEX(FILTER(DISTINCT('Table'),'Table'[T2]<>BLANK()),'Table'[Group],",")
_D2 = CONCATENATEX(FILTER(DISTINCT('Table'),'Table'[T2]<>BLANK()),'Table'[Measure],",")

 

And you will see:

Annotation 2020-06-24 154159.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

 

Create 2 measures as below:

 

Measure= CALCULATE(COUNT('Table'[Group]),FILTER('Table','Table'[UserID]=MAX('Table'[UserID])))
T2 = IF(RANKX(FILTER(ALL('Table'),'Table'[UserID]=MAX('Table'[UserID])&&'Table'[Specialty]=MAX('Table'[Specialty])), 
RANKX(FILTER(ALL('Table'),'Table'[UserID]=MAX('Table'[UserID])&&'Table'[Specialty]=MAX('Table'[Specialty])),CALCULATE(COUNTA('Table'[Group])),,DESC,Dense)+
RANKX(FILTER(ALL('Table'),'Table'[UserID]=MAX('Table'[UserID])&&'Table'[Specialty]=MAX('Table'[Specialty])),CALCULATE(MAX('Table'[Group])),,ASC,Dense)
/COUNTROWS(FILTER(ALL('Table'),'Table'[UserID]=MAX('Table'[UserID]))),,ASC,Dense)<=3,'Table'[Measure 2],BLANK())

 

And you will see:

Annotation 2020-06-24 154239.png

And for D1 and D2,see below:

 

_D1 = CONCATENATEX(FILTER(DISTINCT('Table'),'Table'[T2]<>BLANK()),'Table'[Group],",")
_D2 = CONCATENATEX(FILTER(DISTINCT('Table'),'Table'[T2]<>BLANK()),'Table'[Measure],",")

 

And you will see:

Annotation 2020-06-24 154159.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

Anonymous
Not applicable

 

Thanks for providing me this solution, But I am not able to understand how it can work if there is no specailty  column. I think you are groupby back with specailty  which I am not willing. I want to rank and concat the top3 values only w.r.t each user.

Can you provide some explaination for the same?

harshnathani
Community Champion
Community Champion

HI @Anonymous ,

 

You can try these measures.

 

D1 =
CONCATENATEX (
    TOPN (
        3,
        SUMMARIZE (
            'Table',
            'Table'[UserID],
            'Table'[Specialty],
            'Table'[Group],
            "countof", CALCULATE (
                COUNT ( 'Table'[Group] ),
                FILTER (
                    'Table',
                    'Table'[UserID]
                        = MAX ( 'Table'[UserID] )
                        && 'Table'[Specialty]
                            = MAX ( 'Table'[Specialty] )
                )
            )
        ),
        [countof]
    ),
    'Table'[Group],
    ","
)

 

 

 

D2 =
CONCATENATEX (
    TOPN (
        3,
        SUMMARIZE (
            'Table',
            'Table'[UserID],
            'Table'[Specialty],
            'Table'[Group],
            "countof", CALCULATE (
                COUNT ( 'Table'[Group] ),
                FILTER (
                    'Table',
                    'Table'[UserID]
                        = MAX ( 'Table'[UserID] )
                        && 'Table'[Specialty]
                            = MAX ( 'Table'[Specialty] )
                )
            )
        ),
        [countof]
    ),
    [countof],
    ","
)

 

 

1.jpg

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Anonymous
Not applicable

Thanks for providing me this solution, But I am not able to understand how it can work if there is no specailty  column. I think you are groupby back with specailty  which I am not willing. I want to rank and concat the top3 values only w.r.t each user.

Can you provide some explaination for the same?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors