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.
Hi all, I have a (I think) pretty basic problem but I'm totally new to DAX and I'm really struggling to understand its basic concepts.
I've tried to look on the web at solutions for problems similar to mine, but I keep on hitting walls.
I have a table with a similar content (sorry for the format)
Name Rank List of Items Desidered Outcome
Roger 2 Apples
Roger 3 Oranges
Roger 5 Bananas Bananas
Roger 6 Strawberries
Roger 7 Potatoes
Roger 1 Bananas Bananas
Roger 4 Cherries
Mike 2 Pineapples
Mike 3 Tomatoes
Mike 5 Cherries
Mike 1 Apples Apples
Mike 7 Oranges
Mike 6 Bananas
Mike 4 Apples Apples
I'd like to find the name of the item whose Rank is equal to 1 (for each person) and then write the name of the item in my calculated column (Desidered Outcome) whenever it matches the name in the List of Items column. I know it might seem dumb, but it serves a purpose.
I've tried with LOOKUPVALUE but since the Rank column doesn't have unique values it returns an error, so I know I have to use a FILTER. I've tried to use different combinations of CALCULATE and FILTER but there's something basic I'm missing, because I can't make them work
Thanks for all the help!
Solved! Go to Solution.
@Fabio74
Use the ALLEXCEPT to filter by Person then get the item for rank 1.
Desidered Outcome =
VAR __item =
CALCULATE(
MAX('Table'[Item]),
'Table'[Rank] = 1,
ALLEXCEPT('Table','Table'[Person])
)
return
IF(__item = [Item] , __item)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Hi, @Fabio74
Please try the below whether it suits your case.
Hi, My name is Jihwan Kim.
If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.
Linkedin: linkedin.com/in/jihwankim1975/
Twitter: twitter.com/Jihwan_JHKIM
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Thank you @Jihwan_Kim, I'll try your solution too and hopefully in the next (not to far I hope) future I'll be able to tell the difference between all your suggestions.
Have a nice day!
@Fabio74
Use the ALLEXCEPT to filter by Person then get the item for rank 1.
Desidered Outcome =
VAR __item =
CALCULATE(
MAX('Table'[Item]),
'Table'[Rank] = 1,
ALLEXCEPT('Table','Table'[Person])
)
return
IF(__item = [Item] , __item)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Hey @Fabio74 ,
try the following measure:
Outcome =
VAR vCurrentName = MyTable[Name]
VAR vResult = CALCULATE( MAX( MyTable[List of Items] ), MyTable[Name] = vCurrentName, MyTable[Rank] = 1 )
RETURN
vResult
I think you should take a look about row and filter context:
Row Context and Filter Context in DAX - SQLBI
In the variable vCurrentName I save the name of the row context. That is basically the value of the name column in the current row.
Then I use a CALCULATE to get the item. Be aware that CALCULATE is triggering context transition. I set the filter on the person in the current row and Rank 1. Like this you should get the result you wish.
Dear @selimovd , thank you so much for your quick reply.
I've applied your formula in the test table I've provided above and it works just fine. But if I copy the same formula in my real table, the correct Item description is written only on the row whose Rank is = to 1.
There obviously must be something different between my actual table and the example one, but for the life of me I can't figure out what. In terms of logic it looks (to me) like the exact same thing ... so frustrating.
I'll get back to it with a clearer mind. Thanks for now!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
101 | |
78 | |
75 | |
49 |
User | Count |
---|---|
145 | |
108 | |
107 | |
89 | |
61 |