0
votes

On Power BI Desktop, I am working with multiple conditional IF statements. I have an original table with user IDs and SecondsToOrder, looking like this.

UserID      SecondsToOrder
00001       2320
00002       13
00003       389
00004       95
...         ...

I created a new calculated column MinutesRounded to rounddown seconds into minutes, and now my table is looking like this.

UserID      SecondsToOrder   MinutesRounded
00001       2320             38
00002       13               0
00003       389              12
00004       95               1
...         ...              ...

Now I want to create another column based on my calculated column MinutesRounded, where depending on a number I assign each user to one of the following groups: '< 1 minute' '<15 minutes' and '> 15 minutes'. The end result should look like this.

UserID      SecondsToOrder   MinutesRounded    Lenght
00001       2320             38               > 15 minutes
00002       13               0                < 1 minute 
00003       389              12               < 15 minutes 
00004       95               1                < 1 minute 
...         ...              ...              ... 

I am doing it using DAX by this statement.

Lenght = IF([MinutesRounded]<1,"< 1 minute",IF([MinutesRounded]<15,"<15 minutes", "> 15 minutes"))

And getting a syntax error. Seriously don't understand what is wrong here. Could you please help. The error I am getting is below:

The syntax for '"< 1 minute"' is incorrect. (DAX(IF([MinutesRounded]<1."< 1 minute",IF([MinutesRounded]<15."<15 minutes", "> 15 minutes")))).

For some reason I see dots and brackets appearning in the error which I haven't even typed. How should I fix it?

UPDATE: found the reason was some regional/keyboard setting within POWER BI, and that's why I had to use semicolons instead of commas. The code itself was correct.

1

1 Answers

3
votes

I get no error using your DAX exactly as it is:

= IF([MinutesRounded]<1,"< 1 minute",IF([MinutesRounded]<15,"<15 minutes", "> 15 minutes"))

You can also use SWITCH:

=
SWITCH (
    TRUE (),
    [MinutesRounded] < 1, "< 1 minute",
    [MinutesRounded] < 15, "<15 minutes",
    "> 15 minutes"
)

Thanks