Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Help with IF and Measure

Hi everyone

 

I need help with a IF statement and measure.

 

I have this measure,

BANANAS = IFERROR(IF(HASONEVALUE(TBL_Automation1[Product])=TRUE(),CALCULATE(SUM(TBL_Automation1[Compliant]), TBL_Automation1[Indicator]="BANANAS ")/CALCULATE(SUM(TBL_Automation1[Total]), TBL_Automation1[Indicator]="BANANAS "),CALCULATE(SUM(TBL_Automation1[Compliant]), TBL_Automation1[Indicator]="BANANAS ", ALL(COD_Product[Product]))/CALCULATE(SUM(TBL_Automation1[Total]), TBL_Automation1[Indicator]="BANANAS ",ALL(COD_Product[Product]))),BLANK())

 

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.

Month Value  = IF(MAX(COD_Indicator[Indicator])="Bananas", [BANANAS],FALSE)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

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

Anonymous
Not applicable

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.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.