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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
AlanP514
Post Patron
Post Patron

TOPN With Multiple Columns

Hai All ,
I want to Fetch TOP 10 Keywords Based on different Columns (Clicks, Cost,Impressions)
How it will be Done using DAX 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @AlanP514 ,

I created some data:

vyangliumsft_0-1646117290016.png

Here are the steps you can follow:

1. Create measure.

Clicks_Rank =
RANKX(ALL('Table'),CALCULATE(SUM('Table'[Clicks])),,ASC)
Cost_Rank =
RANKX(ALL('Table'),CALCULATE(SUM('Table'[Cost])),,ASC)
impressions_Rank =
RANKX(ALL('Table'),CALCULATE(SUM('Table'[impressions])),,ASC)

vyangliumsft_1-1646117290018.png

2. Use Enter data to create a Slice Table.

vyangliumsft_2-1646117290018.png

3. Create measure.

Rank =
var _select=SELECTEDVALUE(Slice_Table[Slice])
return
SWITCH(
    TRUE(),
    _select="Click_Rank",[Clicks_Rank],
    _select="Cost_Rank",[Cost_Rank],
    _select="impressions_Rank",[impressions_Rank])
Flag =
IF(
    [Rank]<=10,1,0)

4. Use the [Slice] slicer of Slice_Table, and put [Flag] into Filter, and set is =1.

vyangliumsft_3-1646117290021.png

5. Result:

When Cost_Rank is selected, the top 10 rankings with cost are displayed.

vyangliumsft_4-1646117290021.png

When the selection is impressions_Rank, the top 10 ranking of impressions is displayed.

vyangliumsft_5-1646117290022.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @AlanP514 ,

I created some data:

vyangliumsft_0-1646117290016.png

Here are the steps you can follow:

1. Create measure.

Clicks_Rank =
RANKX(ALL('Table'),CALCULATE(SUM('Table'[Clicks])),,ASC)
Cost_Rank =
RANKX(ALL('Table'),CALCULATE(SUM('Table'[Cost])),,ASC)
impressions_Rank =
RANKX(ALL('Table'),CALCULATE(SUM('Table'[impressions])),,ASC)

vyangliumsft_1-1646117290018.png

2. Use Enter data to create a Slice Table.

vyangliumsft_2-1646117290018.png

3. Create measure.

Rank =
var _select=SELECTEDVALUE(Slice_Table[Slice])
return
SWITCH(
    TRUE(),
    _select="Click_Rank",[Clicks_Rank],
    _select="Cost_Rank",[Cost_Rank],
    _select="impressions_Rank",[impressions_Rank])
Flag =
IF(
    [Rank]<=10,1,0)

4. Use the [Slice] slicer of Slice_Table, and put [Flag] into Filter, and set is =1.

vyangliumsft_3-1646117290021.png

5. Result:

When Cost_Rank is selected, the top 10 rankings with cost are displayed.

vyangliumsft_4-1646117290021.png

When the selection is impressions_Rank, the top 10 ranking of impressions is displayed.

vyangliumsft_5-1646117290022.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thank you for the wonderful explanation

amitchandak
Super User
Super User

@AlanP514 , these are measures (of with sum) you need create 3 measures

Assuming you have measures

Clicks, Cost,Impressions

Top 10= calculate([Clicks], TOPN(10,allselected(Table[keywords]),[Clicks],DESC), values(Table[keywords]))

 

Top 10= calculate([Cost], TOPN(10,allselected(Table[keywords]),[Impressions],DESC), values(Table[keywords]))

 

Top 10= calculate([Impressions], TOPN(10,allselected(Table[keywords]),[Impressions],DESC), values(Table[keywords]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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