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
Anonymous
Not applicable

DAX “multiple columns” error when trying to return the Nth ranked text value

I was working on a solution to calculate something similar to Qlikview's FirstSortedValue in DAX for Power BI. To my knowledge there is no solution out of the box to get the functionality of getting a text value (much like the category) which by its rank is in an nth position.

My question is: Why does this work on a single column, but returns a multiple column error when used on a table?

CALCULATE(SAMPLE(1, FILTER('table_name', RANKX(ALL('table_name'[column_name]), CALCULATE(COUNT('table_name'[column_name])),,,skip) = Nth), TRUE()))

a different variation as well:

CALCULATE(SAMPLE(1, VALUES('table_name'[column_name]), TRUE()), FILTER('table_name', RANKX(ALL('table_name'[column_name]), CALCULATE(COUNT('table_name'[column_name])),,,Dense) = Nth))

Either of these and many more of my attempts work when it is a single column, but why would this not work when used on a table with multiple columns? It should return a sample of 1 text value according to the Nth rank I choose? Akin to answering a question of "What is the Nth top selling product name according to salescount?".

I am stumped, still trying to find an answer. Firstnonblank is not an option, because I do not care for a solution to get the 1st ranked answer only; do not suggest that. 🙂

Other than that - please help, I feel I am close... 🙂

1 ACCEPTED SOLUTION
Anonymous
Not applicable

**EDIT: Oct 23 2018
Here it is! The final succinct version: works great!**
Measure =

VAR Nth = [number] RETURN CONCATENATEX(DISTINCT('table_name'[column_name]), CALCULATE(FILTER(VALUES('table_name'[column_name]), RANKX(ALL('table_name'[column_name]), CALCULATE(COUNT('table_name'[column_name])),,,Dense) = Nth)),",")

View solution in original post

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

I could use SAMPLE function in a calculated table without any error prompt. But I cannot understand what is the purpose of "= Nth" in above formula. Could you please provide more description with some sample data? And please show us your desired output.

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

**EDIT: Oct 23 2018
Here it is! The final succinct version: works great!**
Measure =

VAR Nth = [number] RETURN CONCATENATEX(DISTINCT('table_name'[column_name]), CALCULATE(FILTER(VALUES('table_name'[column_name]), RANKX(ALL('table_name'[column_name]), CALCULATE(COUNT('table_name'[column_name])),,,Dense) = Nth)),",")

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.