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.
I need the dax for an "if this condition, calculate this, otherwise, calculate this" for each status in the table
If the balance is 0 then the total of Status is based on "price', if the balance is greater than 0 (or otherwise), then the total is based on "balance"
(my dax below does not work)
Total Status A=if(Transaction [balance] =0,
Calculate (
Sum (Transaction [price] ),
Transaction [status] = A, Sum (Transaction [balance]))))
Transaction Table | ||
balance | price | |
StatusA | 0 | 10 |
StatusA | 10 | 20 |
StatusA | 20 | 30 |
StatusA | 0 | 10 |
StatusB | 0 | 0 |
StatusB | 10 | 0 |
StatusB | 20 | 0 |
StatusB | 0 | 10 |
StatusB | 10 | 10 |
StatusB | 10 | 0 |
StatusC | 0 | 10 |
StatusC | 10 | 0 |
StatusC | 0 | 10 |
For example, if looking at Status A for a card visual with the total
If the balance is 0 then the total of Status A is based on "price’, if the balance is greater than 0 (or my “otherwise”), then the total is based on “balance”
In this case, the total for status A = 50
line 1 =10 (based on price because balance is =0)
line 2=10 (based on balance because balance > 0)
line 3 =20 (based on balance because balance > 0)
line 4 = 10 (based on price because balance is =0)
Thank you in advance!
Solved! Go to Solution.
Here was the solution in case anyone needs something similar.
Create a calc column
Then a measure:
I would suggest using a SWITCH(TRUE() ...) statement.
https://docs.microsoft.com/en-us/dax/switch-function-dax
@Greg_Deckler
thanks for the idea.
I was seeing that prior to me asking the question but I could not get it written out correctly. If anyone else can assist, would appreciate help getting past the issue.
I am sure there an equivalent in Power Query, in DAX it would be something like:
Measure =
VAR __status = MAX(Transaction[status]
VAR __balance = MAX(Transaction[balance]
RETURN
SWITCH(TRUE(),
__status = "status A",SUM(Transaction[price]),
__balance = "0",SUM(Transaction[balance])
)
Well, I appreciate you trying. I figured out after trying a few times, I had to add in the commas, etc. since you didn't add them but in the end could't figure out what is between Return and Switch so it made it look like one word in Dax, thus an error. I tried comma, etc.
Anyway, if anyone else can assist. This might have worked but I'm new to some DAX and can't seem to find how to correct it.
Not sure if it likes the _status and _balance at the end either (red error lines) but it's only giving me an error on the Return syntax
Here was the solution in case anyone needs something similar.
Create a calc column
Then a measure:
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 |
---|---|
106 | |
97 | |
80 | |
67 | |
63 |
User | Count |
---|---|
147 | |
110 | |
108 | |
85 | |
64 |