Forum Discussion

adi38612's avatar
adi38612
Frequent Visitor
1 year ago
Solved

Power BI: Dynamic Top N Filtering Based on Selection?

I have a Power BI table with three columns: ID, Title, and Name.   I created two clustered bar charts: Chart 1 → Shows the Top 3 Names (Y-axis: Name, X-axis: Count of ID). Chart 2 → Shows the To...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi adi38612 ,
    According to your question, you want to filter the first table (e.g. name) and then sort based on the values filtered by the first table right?
    We can first use the RANKX function on the name column and total column sorting, and then create a new Topn table to Topn table to filter you need the first few rankings, and finally write a measure to put into each chart to achieve your needs!

    Name ID Count = 
     CALCULATE(COUNT('Table'[ID]), ALLEXCEPT('Table', 'Table'[Name]))
    Rankx Name = 
    RANKX(ALLSELECTED('Table'[Name]),[Name ID Count],,DESC,Dense)
    Top N = GENERATESERIES(1, 10, 1)
    Top N Names = IF([Rankx Name]  <=SELECTEDVALUE('Top N'[Top N]), 1, 0)

    If you have any other questions, you can check out the pbix file I uploaded, I hope it helps, and I'd be honored if I could solve your problem!

    Hope it helps!

    Best regards,
    Community Support Team_ Tom Shen

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