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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
braga_felipe
Frequent Visitor

TOPN FUNCTION TO SHOW THE 'N VALUE'

Hello everyone, 

I want to create a measure to return me the N value of a ranked column but i don't no where i'm doing wrong.

For example, i want to show only the second value of 'Value_1' using the 'Rank' column as the mandatory indicator. This measure must work when i filter the different scenarios with a filter box ('Scenario' column).

 

image.png

Could anyone help me? Thank you so much.

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @braga_felipe ,

 

Here are the steps you can follow:

1. In Power query. Add Column – Index Column – From 1.

vyangliumsft_0-1668069835210.png

2. Create measure.

Flag =
IF(
    MAX('Table'[Index])=2,1,0)

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_1-1668069835212.png

4. Result:

vyangliumsft_2-1668069835221.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

5 REPLIES 5
v-yangliu-msft
Community Support
Community Support

Hi  @braga_felipe ,

 

Here are the steps you can follow:

1. In Power query. Add Column – Index Column – From 1.

vyangliumsft_0-1668069835210.png

2. Create measure.

Flag =
IF(
    MAX('Table'[Index])=2,1,0)

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_1-1668069835212.png

4. Result:

vyangliumsft_2-1668069835221.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

v-yangliu-msft
Community Support
Community Support

Hi  @braga_felipe ,

 

Here are the steps you can follow:

1. In Power query. Add Column – Index Column – From 1.

vyangliumsft_0-1667977469287.png

2. Create calculated column.

 

Flag =
RANKX(FILTER(ALL('Table'),[Scenairo]=EARLIER('Table'[Scenairo])),[Index],,ASC)

 

3. Create measure.

 

Rank =
RANKX(FILTER(ALL('Table'),[Scenairo]=MAX('Table'[Scenairo])),CALCULATE(SUM([Index])),,ASC)

 

4. Result:

vyangliumsft_1-1667977469289.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

Hello!
I understood what you did, but it is not the entire solution i am trying to do. 
For example, using this measures, i want to get only the rank 2 and show the value 50. 

Thank you.

amitchandak
Super User
Super User

@braga_felipe , if you want use rank column, you can use it filter use before filter. Of can use what if to filter that

https://docs.microsoft.com/en-us/power-bi/desktop-what-if

 

or what if with TOPN

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

 

Hello, thank you for your answer.

Have a another way to dont use the a rank column? I mean, use only the order that i have in the original database.

Thank you.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.