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
tonyclifton
Helper III
Helper III

Measure to filter product by highest rating

Hello community,

I need to create a measure to filter below table by product and its highest rating.
Unbenannt.PNG


Output:
s.PNG

 

This measure seems fine:

Max = CALCULATE(MAX(Table1[Rating]);ALLEXCEPT(Table1;Table1[ProductID]))

However I need to show the Rating column, so I am guessing an IF statement is needed here but I cannot get it to work.

Can you help?

Thank you.

1 ACCEPTED SOLUTION

I couldn't get the rank part to work, so in the end I was able to do it like this:

isMax = 
var a = CALCULATE(MAX(Table1[Rating]);ALLEXCEPT(Table1;Table1[ProductID]))

var x = if(a <= Table1[Rating];1;0)
return x

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

hi

the "output" that you show is the desidered output?

yes @Anonymous that's the desired output.
My Idea is to have a measure that is either 1 or 0 for each product and rating so that I can use it in a page level filter.

Anonymous
Not applicable

ok so the best way to do so is to use a calculated column with the RANKX dax. You won't have "1 or 0" but a number from 1 to N where 1 is the highest

 

Create a custom column and use this formula (i assume that the grouping is at productId level)


Ordering = 
VAR thisProductId = YourTableName['ProductID']

RETURN
RANKX(FILTER(YourTableName;YourTableName['ProductID']=thisProductId);YourTableName['Rating'];DESC)

you should have a number from 1 to N where 1 is the highest value in each group

I couldn't get the rank part to work, so in the end I was able to do it like this:

isMax = 
var a = CALCULATE(MAX(Table1[Rating]);ALLEXCEPT(Table1;Table1[ProductID]))

var x = if(a <= Table1[Rating];1;0)
return x
Anonymous
Not applicable

Hi

it should work, the logic is the same, but with this method you will get only 0-1, whereas in my method it's 1 to N.
Still, that's what you need so good job!

Anonymous
Not applicable

in fact the formula i wrote won't work, I realize now, since it isnt' wrapped in a CALCULATE (so the row context does not switch to a filter context). 

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.