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
shaildesai
Frequent Visitor

Top N Function

I used Top N and passed a measure (selected value of a slicer of 1 to 10 values) as the first parameter to make it dynamic. But it is returning no records and showing blank. Any help?

1 ACCEPTED SOLUTION

Hi @shaildesai,

AFAIK, selectedvalue function is used to get the current selection value, it does not work for multiple selected values. If you need to handle multiple/not selections, I think you need to add the 'alternate Result' parameter in your function to handle multiple values scenarios.

SELECTEDVALUE function - DAX | Microsoft Docs

In addition, current power bi does not support creating dynamic calculated column/table based on filter/slicer selections, they are working on different data levels and you can use child level to affect its parent. I'd like to suggest you use the query parameter and convert it to a table, then you can extract value from that table for expression calculations.

Notice: the data level of power bi.

Database(external) -> query table(query, custom function, query parameters) -> data model table(table, calculate column/table) -> data view with virtual tables(measure, visual, filter, slicer)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @shaildesai,

Can you please share a pbix or some dummy data that keep raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft 

 

Here is the pbix file: 

https://drive.google.com/file/d/1XhqnWw1WEv20rLXIDLZgPOTbY8IMeatp/view?usp=sharing

 

I want to see the Top N Orders table where N will be the value selected in the slicer. 

Hi @shaildesai,

AFAIK, selectedvalue function is used to get the current selection value, it does not work for multiple selected values. If you need to handle multiple/not selections, I think you need to add the 'alternate Result' parameter in your function to handle multiple values scenarios.

SELECTEDVALUE function - DAX | Microsoft Docs

In addition, current power bi does not support creating dynamic calculated column/table based on filter/slicer selections, they are working on different data levels and you can use child level to affect its parent. I'd like to suggest you use the query parameter and convert it to a table, then you can extract value from that table for expression calculations.

Notice: the data level of power bi.

Database(external) -> query table(query, custom function, query parameters) -> data model table(table, calculate column/table) -> data view with virtual tables(measure, visual, filter, slicer)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@shaildesai , TOPN should use like

Top3 = calculate(sum(Table1[sales]),TOPN(3,allselected(table[Customer]),sum(Table1[sales]),DESC), values(table[Customer]))

 

In place of 3 you can use what if

https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

 

Check

TOPN: https://www.youtube.com/watch?v=QIVEFp-QiOk&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=42

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.