Forum Discussion
JayB
6 years agoNew 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 t...
Greg_Deckler
6 years agoCommunity Champion
I'll take a closer look in a minute, but in general, avoid nested IF statements and use SWITCH instead. Way cleaner.
- JayB6 years agoNew 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_Deckler6 years agoCommunity 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" )- JayB6 years agoNew Member
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.: