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

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.

Reply
JayB
New Member

Problem using IF with new column (Syntax error)

Hello,

 

I'm following this guide ( https://insightsoftware.com/blog/working-with-weeks-in-power-bi/ ) to get week numbers, day numbers and names for my dataset. I'm able to add 2 new columns for the week/day numbers just like in the guide.
I'm failing at the step to add the day names column.

I'm adding the column with the following code:

 

Day Name = IF('123it_otrs time_accounting'[Week Day]=1,"Monday",
IF('123it_otrs time_accounting'[Week Day]=2, "Tuesday",
IF('123it_otrs time_accounting'[Week Day]=3, "Wednesday",
IF('123it_otrs time_accounting'[Week Day]=4, "Thursday",
IF('123it_otrs time_accounting'[Week Day]=5, "Friday",
IF('123it_otrs time_accounting'[Week Day]=6, "Saturday", "Sunday"))))))

 

 and I'm getting the following error:

 

The syntax for '"Monday"' is incorrect. (DAX(IF('123it_otrs time_accounting'[Week Day]=1."Monday",IF('123it_otrs time_accounting'[Week Day]=2. "Tuesday",IF('123it_otrs time_accounting'[Week Day]=3. "Wednesday",IF('123it_otrs time_accounting'[Week Day]=4. "Thursday",IF('123it_otrs time_accounting'[Week Day]=5. "Friday",IF('123it_otrs time_accounting'[Week Day]=6. "Saturday", "Sunday")))))))).

 

 

I'm not sure wher I'm going wrong and I'm starting to think the issue is that I have to use ' ' to access my columns?

 

14 REPLIES 14
Greg_Deckler
Super User
Super User

I'll take a closer look in a minute, but in general, avoid nested IF statements and use SWITCH instead. Way cleaner.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Good comment, (I agree), but I'm getting the exact same error:

=SWITCH('123it_otrs time_accounting'[Week Day], 1, "Monday", 2, "Tuesday", 3, "Wednesday", 4, "Thursday", 5, "Friday", 6, "Saterday", 7, "Sunday") 

Unexpected expression starting at "Monday".

 

I'm very new to this and still following guides, so I may be failing to grasp the basic concepts here.

Yeah, that's bizarre because I copied and pasted your code and it worked perfectly for me. Perhaps something wrong with quotes or double quotes?

 

Both of these worked, PBIX is attached.

 

This is a column, right?

 

Day Name = IF('123it_otrs time_accounting'[Week Day]=1,"Monday",
IF('123it_otrs time_accounting'[Week Day]=2, "Tuesday",
IF('123it_otrs time_accounting'[Week Day]=3, "Wednesday",
IF('123it_otrs time_accounting'[Week Day]=4, "Thursday",
IF('123it_otrs time_accounting'[Week Day]=5, "Friday",
IF('123it_otrs time_accounting'[Week Day]=6, "Saturday", "Sunday"))))))


Day Name 2 = 
    SWITCH([Week Day],
        1,"Monday",
        2,"Tuesday",
        3,"Wednesday",
        4,"Thursday",
        5,"Friday",
        6,"Saturday",
        "Sunday"
    )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you for attaching the example file.

When I open the file, it's good, when I select the column, I see the expression, it gives me an error and it breaks.:

Capture-IFAIL.JPG

What is the language version of your Desktop? 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I'm on a Windows 10 Pro, The display language is set to English (United States), The preferred languages are "English (Belgium)"/"English (United Kingdom)".

I did not realise this might work like Office, where formulas follow the language. But it should be english.

In the powerBI options, regional settings, I forced everything to English (United states), but still the same issue.

Wait, try semi-colons instead of commas. @JayB 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Googling I also found a post where they suggested to use ;, is this what you mean?

 

02.PNG

 

The "intellisense?" example does show me to use ,

01.png

 

Using integers instaid of strings does work. So it's something about the strings.

03.PNG

 

OK, try single quotes??


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

OK, this is highly strange. File | Options and settings | Options | Diagnostics, What version of the Desktop?

 

Also, under Regional Settings what are those:

image.png


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I'm on version 2.79.5768.721 64-bit (March 2020).

I ran PowerBI on my local machine, and your example file ran just fine. (I'm using a VM and RDP to it).
In the VM I've set all regional settings to the United states, I've manually set all powerbi regional settings to united states (This where on that already) and rebooted. And now it works.

 

To conclude. I want to apologise for wasting your time, this was not a DAX question, but "how do I use powerbi". (I sure wasted a lot of time this week trying to gras why even the most basic things failed for me). I didn't realise this worked like Excel, where if you change the language, formulas change.

 

Thank you for your help!

No worries @JayB I've just been working on a blog post and answering forum questions most of the day. Nothing to do with everything shut down over COVID-19!!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Right, sry, I didn't bother to post that, but I have tried that. Same issue. 😕

04.png

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors