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

DAX to get largest 3 numbers in a series of columnby row

Hello

I am trying to find the top 3 values per row for a series of columns and bind it to the bar chart

 


Example:

 

ID

Column2

Column3

Column4

Column5

Column6

Column7

Column8

Column9

Column10

Column11

Column12

Column13

1

5

1

1

0

2

5

8

2

0

1

12

100

2

0

0

22

0

0

0

0

0

10

0

1

200

 

Result:

 

ID

Column13

Column12

Column8

Column4

Column10

1

100

12

8

  

2

200

  2210

 

 

I need a way to determine the value of 13 columns

 

Thanks in advance

1 ACCEPTED SOLUTION

@KarthikeyanS,

 

Unpivot Columns in Query Editor, then use Matrix visual and drag measure below to Values.

Measure =
IF (
    RANKX ( ALLSELECTED ( Table1[Attribute] ), CALCULATE ( SUM ( Table1[Value] ) ) )
        <= 3,
    SUM ( Table1[Value] )
)
Community Support Team _ Sam Zha
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

4 REPLIES 4
Stachu
Community Champion
Community Champion

can you unpivot the data so the columns would be in rows? you could still present it in the way the 2nd table is formatted but the code get's much more simple



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Thanks for your reply.

 

I unpivotted table and managed to put top 3 filter in "Visual filter", but the column names are not changing based on ID. It's same for all ID.

@KarthikeyanS,

 

Unpivot Columns in Query Editor, then use Matrix visual and drag measure below to Values.

Measure =
IF (
    RANKX ( ALLSELECTED ( Table1[Attribute] ), CALCULATE ( SUM ( Table1[Value] ) ) )
        <= 3,
    SUM ( Table1[Value] )
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

I have 3 areas calculated as Area1, Area2 and Area3 in different columns. I'd like to get the 2nd highest area among the 3. 

 

How do I do this in the dax level instead of using a matrix visual and a measure? 

 

Your solution would be of great help.

 

Thanks in advance.

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.