Forum Discussion
DominikW
8 years agoFrequent Visitor
[Advanced Editor] Multiple if statement in M Script
Hello everyone, is it possible to create multiple if statement? I am asking here because I couldn't find any normal tutorial for this. If I use the code like this I am getting error "Token Identi...
- 8 years ago
Well, you can have multiple if statements as in the query below.
I included a "let .. in" statement for Monday, just to illustrate how that would look like.
let Output = if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 0 then let InnerOutput = "Monday" in InnerOutput else if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 1 then "Tuesday" else if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 2 then "Wednesday" else if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 3 then "Thursday" else if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 4 then "Thank God it's Friday" else "Weekend!!" in OutputIn general the structure of a query is like:
let step1 = formula, step2 = formula, ... stepn = formula in stepnIt is not possible to create an if ... then ... else statement without a step name.
MarcelBeug
Community Champion
8 years agoWell, you can have multiple if statements as in the query below.
I included a "let .. in" statement for Monday, just to illustrate how that would look like.
let
Output = if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 0
then let InnerOutput = "Monday"
in InnerOutput
else if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 1
then "Tuesday"
else if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 2
then "Wednesday"
else if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 3
then "Thursday"
else if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 4
then "Thank God it's Friday"
else "Weekend!!"
in
Output
In general the structure of a query is like:
let
step1 = formula,
step2 = formula,
...
stepn = formula
in
stepnIt is not possible to create an if ... then ... else statement without a step name.