Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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 Identifier expected.", I am trying to create historical data for dataset for past 5 days.
if Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 0 then (let Source = Oracle.Database("LINK", [HierarchicalNavigation=true]), NAME = Source{[Schema="NAME"]}[Data], RENAME = NAME{[Name="DATASET"]}[Data], ConvertedPath = Text.Replace("PATHFORFILE", "\", "/"), RScript = R.Execute("write.csv(NAME,"""&ConvertedPath&""") output <- NAME ",[NAME=NAME]), output = RScript{[Name="FILENAME"]}[Value] in output) else (let Source = Csv.Document(File.Contents("PATHOFFILE.csv"),[Delimiter=",", Columns=, Encoding=, QuoteStyle=QuoteStyle.None]), #"Changed Type" = Table.TransformColumnTypes(Source,{COLUMNS}), #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{COLUMNS}),
/*IF AGAIN*/
if
Date.DayOfWeek(DateTime.LocalNow(), Day.Monday) = 1
then
(let
Source = Oracle.Database("LINK", [HierarchicalNavigation=true]),
NAME = Source{[Schema="NAME"]}[Data],
RENAME = NAME{[Name="DATASET"]}[Data],
ConvertedPath = Text.Replace("PATHFORFILE", "\", "/"),
RScript = R.Execute("write.csv(NAME,"""&ConvertedPath&""")
output <- NAME
",[NAME=NAME]),
output = RScript{[Name="FILENAME"]}[Value]
in
output)
else
(let
Source = Csv.Document(File.Contents("PATHOFFILE.csv"),[Delimiter=",", Columns=, Encoding=, QuoteStyle=QuoteStyle.None]),
#"Changed Type" = Table.TransformColumnTypes(Source,{COLUMNS}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{COLUMNS}),
/*IF AGAIN*/
Solved! Go to Solution.
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 Output
In general the structure of a query is like:
let step1 = formula, step2 = formula, ... stepn = formula in stepn
It is not possible to create an if ... then ... else statement without a step name.
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 Output
In general the structure of a query is like:
let step1 = formula, step2 = formula, ... stepn = formula in stepn
It is not possible to create an if ... then ... else statement without a step name.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
76 | |
71 | |
56 | |
39 | |
35 |
User | Count |
---|---|
66 | |
66 | |
59 | |
53 | |
45 |