Forum Discussion
run multiple statements in if then else
One other question. I am adding a Custom Column using Power Query in Power BI. I have and if statement here:
if Text.Contains( [Start Time],"+")
then
Text.Replace([Start Time],"+","");;
Date.AddDays([Date],1)
else
[Date]
How do I next those two statements if the condition is true?
You cannot do two things in a custom column. You can test two or more things, but the thing you do is one thing, one formula. What you are saying is:
if [Start Time] has a "+" symbol, then return [Start Time] and replace the "+" with a ",", and also return the [Date] plus one day, so you are asking to return two things to one column. Cannot do it.
You'd to add two custom columns, each doing one thing.
You can test multiple things though, so as an example:
if Text.Contains([Start Time],"+") and Date.AddDays([Date],1) > DateTime.Date(DateTime.LocalNow()) then do-something-here else do-something-elseThat would only do "do-something-here" if the Start Time had a "+" symbol and the [Date] was in the future, otherwise it woudl "do-something-else"
But you cannot do 2 things. Only 1.
1 Reply
- edhansCommunity Champion
You cannot do two things in a custom column. You can test two or more things, but the thing you do is one thing, one formula. What you are saying is:
if [Start Time] has a "+" symbol, then return [Start Time] and replace the "+" with a ",", and also return the [Date] plus one day, so you are asking to return two things to one column. Cannot do it.
You'd to add two custom columns, each doing one thing.
You can test multiple things though, so as an example:
if Text.Contains([Start Time],"+") and Date.AddDays([Date],1) > DateTime.Date(DateTime.LocalNow()) then do-something-here else do-something-elseThat would only do "do-something-here" if the Start Time had a "+" symbol and the [Date] was in the future, otherwise it woudl "do-something-else"
But you cannot do 2 things. Only 1.