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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

IF statement in DAX is correct but error keeps showing

Please help!Capture.PNG

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Problem solved!

 

Explanation of solutions:

 

To summarize, all errors were related to language settings in both PowerBI and desktop as tex628 suggested.

 

My initial settings were English (United States) in both PowerBI and desktop regional settings since two months - everything worked great until yesterday when these errors suddenly appeared!

 

Following tex628's hints, I switched to English (Belgium), the errors were still there - but my colleague Marc found a workaround by using parenthesis to separate all expressions; all errors were gone.

 

Finally, I tried to use the same settings as tex628's, meaning all the settings are in English (United Kingdom), then all the original codes are free of errors and there is no need to use the additional workaround mentioned above.

 

Problem solved and my credits to tex628!

 

Thank you everyone for your help!!!

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Thank you for your answers.
I have lots of similar errors where syntaxes are surely correct but similar errors keep show up. So I post them all, hopefully you can see the root problem better.


 
Syntax 1
SWITCHcolumn = SWITCH(
   TRUE(),
   'Sales'[QuantitySold] <5, "bad",
   'Sales'[QuantitySold] <10, "better",
   'Sales'[QuantitySold] <15, "good",
   "great"
)
 
Error 1:
The syntax for '"bad"' is incorrect. (DAX(SWITCH( TRUE(), 'Sales'[QuantitySold] <5. "bad", 'Sales'[QuantitySold] <10. "better", 'Sales'[QuantitySold] <15. "good", "great"))).
 
Syntax 2
IfThenPrice = IF(ProductPrice[Price] > 3, "expensive", "cheap")
 
Error 2: The syntax for '"expensive"' is incorrect. (DAX(IF(ProductPrice[Price] > 3. "expensive", "cheap"))).
 
Syntax 3
IfThenSales = IF('Sales'[QuantitySold]>15, "great",
    IF('Sales'[QuantitySold]>5, "good", "bad"))
 
Error 3:
The syntax for '"great"' is incorrect. (DAX(IF('Sales'[QuantitySold]>15. "great", IF('Sales'[QuantitySold]>5. "good", "bad")))).
 
Syntax 4:
DiscountYN =
    VAR DiscountAmount = ,8
    VAR DiscountApplied = Sales[TotalProductSales] * DiscountAmount

RETURN
    IF (Sales[TotalProductSales] > 100, DiscountApplied,
    Sales[TotalProductSales])
 
Error 4:
The syntax for ',' is incorrect. (DAX( VAR DiscountAmount = ,8 VAR DiscountApplied = Sales[TotalProductSales] * DiscountAmountRETURN IF (Sales[TotalProductSales] > 100. DiscountApplied, Sales[TotalProductSales]))).
 
Capture1.PNGCapture2.PNGCapture3.PNGCapture4.PNG
 
 
tex628
Community Champion
Community Champion

Honestly I'm not quite sure what could be wrong here, it might be related to your regional settings. 

I believe the issue in error 4 is that the "," should be replaced with a "."

Could you please provide the locale in PBI desktop & your desktop regional settings: 
image.png

image.png


Connect on LinkedIn
Anonymous
Not applicable

 

 

 

 

 

Capture5.PNGCapture6.PNG

Anonymous
Not applicable

Problem solved!

 

Explanation of solutions:

 

To summarize, all errors were related to language settings in both PowerBI and desktop as tex628 suggested.

 

My initial settings were English (United States) in both PowerBI and desktop regional settings since two months - everything worked great until yesterday when these errors suddenly appeared!

 

Following tex628's hints, I switched to English (Belgium), the errors were still there - but my colleague Marc found a workaround by using parenthesis to separate all expressions; all errors were gone.

 

Finally, I tried to use the same settings as tex628's, meaning all the settings are in English (United Kingdom), then all the original codes are free of errors and there is no need to use the additional workaround mentioned above.

 

Problem solved and my credits to tex628!

 

Thank you everyone for your help!!!

tex628
Community Champion
Community Champion

Regional settings can be a mess! I'm glad that i worked out 🙂


Connect on LinkedIn
tex628
Community Champion
Community Champion

Expand the entire dax editor and take another picture:
image.png


Connect on LinkedIn
OwenAuger
Super User
Super User

@Anonymous 

I'm afraid I can't replicate your error.

My first hunch was that some invalid character has crept into the formula, but I couldn't find any way of producing the same error message.

 

Could you try re-typing the formula from scratch.

 

Otherwise, could you share a PBIX exhibiting the error?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.