Forum Discussion

JayB's avatar
JayB
New Member
6 years ago

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

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

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

    • JayB's avatar
      JayB
      New Member

      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.

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        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"
            )