Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hi,
I'm stuck on this annoying problem. I would like to indicate where the highest cost arises based on
- NAME
- ALIAS
- BRANCH
- MONTH
Now my following MAX(COST)-column makes the following calculation:
IF(CALCULATE(MAX('TABLE'[COST]),
And my INDICATOR-column then makes it as a "1" if the entry is the maximum.
I have following table
ID | NAME | ALIAS | BRANCH | MONTH | YEAR | COST | MAX(COST) | INDICATOR |
1 | VICTOR | VLA | CAR | 1 | 2020 | 620 | 620 | 1 |
2 | VICTOR | VLA | CAR | 1 | 2020 | 453 | ||
3 | VICTOR | VLA | CAR | 1 | 2020 | 620 | 620 | 1 |
4 | VICTOR | VLA | CAR | 1 | 2020 | 249 | ||
5 | VICTOR | VLA | TRUCK | 2 | 2020 | 1219 | 1219 | 1 |
6 | CARL | CHO | CAR | 2 | 2020 | 310 | 310 | 1 |
7 | CARL | CHO | TRUCK | 2 | 2020 | 918 | ||
8 | CARL | CHO | TRUCK | 2 | 2020 | 1328 | 1328 | 1 |
But, I only want my INDICATOR to count the earliest MAX-value, i.e. the second "620" given the same filters should just be blank as following:
ID | NAME | ALIAS | BRANCH | MONTH | YEAR | COST | MAX(COST) | INDICATOR |
1 | VICTOR | VLA | CAR | 1 | 2020 | 620 | 620 | 1 |
2 | VICTOR | VLA | CAR | 1 | 2020 | 453 | ||
3 | VICTOR | VLA | CAR | 1 | 2020 | 620 | ||
4 | VICTOR | VLA | CAR | 1 | 2020 | 249 | ||
5 | VICTOR | VLA | TRUCK | 2 | 2020 | 1219 | 1219 | 1 |
6 | CARL | CHO | CAR | 2 | 2020 | 310 | 310 | 1 |
7 | CARL | CHO | TRUCK | 2 | 2020 | 918 | ||
8 | CARL | CHO | TRUCK | 2 | 2020 | 1328 | 1328 | 1 |
As you can se from the table MAX(COST) is blank for ID='3'. How do I make sure my INDICATOR takes this into account?
Thanks in advance.
@Anonymous here is the measure and the result
Max Cost =
VAR __table =
ALLEXCEPT (
'Cost',
'Cost'[MONTH],
'Cost'[NAME],
'Cost'[ALIAS],
'Cost'[BRANCH]
)
VAR __id =
CALCULATE (
MIN ( Cost[ID] ),
TOPN ( 1, __table, CALCULATE ( MAX ( Cost[COST] ) ), DESC )
)
VAR __return =
IF ( MIN ( Cost[ID] ) = __id , 1 )
RETURN __return
Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
When I try the code it just gives me the circular reference error. How can that be?
Hi @Anonymous ,
You need to copy the code to measure instead of calculated column.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
What if I don't have an ID-column? How should I then approach it? I know it sounds silly, but making this code work without using the ID would be better in my case 🙂
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
87 | |
87 | |
87 | |
67 | |
49 |
User | Count |
---|---|
135 | |
113 | |
100 | |
68 | |
67 |