Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi everyone
I need help with a IF statement and measure.
I have this measure,
And this measure on the main table, what i need is to have if the indicator column reads bananas then it should performe the [BANANAS] measure.
Solved! Go to Solution.
Hi @Anonymous
I'll give you some hints. First, get rid of ISERROR. This function is not necessary and, indeed, it's always harmful. Instead of raw division, use the function DIVIDE (this will let you also remove ISERROR). Next, format the code to be human-readable; currently, it's not DAX. Then do not equate a logical function HASONEVALUE to a logical value. This is unnecessary since HASONEVALUE returns a logical value already: TRUE or FALSE. Next, if you have more than 2 conditions to check, use SWITCH instead of IF.
Just please tidy up the code because it's not only ugly. It's unreadable. Such code is not DAX, as Alberto Ferrari and Marco Russo say, and they know very well what they say and why.
I don't know what it is you want to do with [Month Value], so can't help you with it. However, I'd question your decision to make a measure that returns a mixture of different types: a logical value and a numeric value. This is not the correct way to do things.
By the way, if you want to format your code correctly, you can do it here: DAX Formatter by SQLBI
Hi @Anonymous
I'll give you some hints. First, get rid of ISERROR. This function is not necessary and, indeed, it's always harmful. Instead of raw division, use the function DIVIDE (this will let you also remove ISERROR). Next, format the code to be human-readable; currently, it's not DAX. Then do not equate a logical function HASONEVALUE to a logical value. This is unnecessary since HASONEVALUE returns a logical value already: TRUE or FALSE. Next, if you have more than 2 conditions to check, use SWITCH instead of IF.
Just please tidy up the code because it's not only ugly. It's unreadable. Such code is not DAX, as Alberto Ferrari and Marco Russo say, and they know very well what they say and why.
I don't know what it is you want to do with [Month Value], so can't help you with it. However, I'd question your decision to make a measure that returns a mixture of different types: a logical value and a numeric value. This is not the correct way to do things.
By the way, if you want to format your code correctly, you can do it here: DAX Formatter by SQLBI
Hi @Anonymous
Thank you for your reply. indeed this is not the most readble formula, but it was what i got in this project, i have started to change the formula to a better look.
Thank you once more.
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |