Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
1 like 0 dislike
1.2k views
in Power BI by 24 25 33

I am trying to add Nested IF in Power Query in Power BI to perform multiple checking on the specific field but I got "Token expected" in the custom column editor in Power Query in Power BI!

if([Start Date]>=Today(), "NotStarted",if([End Date]<Today(),"Finished"),"UnMeashred")

nested if in power query

I just used the same IF condition used in my DAX measure but it's now working and I need to know How can I use Nested IF in Power Query in Power BI?


1 Answer

2 like 0 dislike
by 159 186 375
selected by
 
Best answer

How to use Nested IF in Power Query in Power BI?

First of all, you should be aware of the DAX syntax can't be used in Power Query, you can only use M Language to write formulas in Power Query in Power BI.

What's M language?

  1. M language is a mashup query language for Power Query.
  2. M language stands for Data Mashup or Data Modeling.
  3. M language is a functional, case-sensitive language similar to F#, which can be used with Power Query in Excel, Get & Transform in Excel 2016, and Power BI Desktop.
  4. M language can be only used in Power Query Editor in Power BI.

Note: M Language and DAX are supported by Power BI to manage, manipulate, filter, and analyze the data. but they are not the same and not dependent upon each other and each one has a different syntax, structure, and logic. Read more at Power BI: DAX Vs M Language


Using Nested IF in Power Query in Power BI

You can use the below syntax to build a Nested IF statement in Power Query in Power BI

if Condition 1 then "Result1" 
else if condition 2 then "Result 2" 
else if Condition3 then "Result 3" 
else "Result4"

In your case, try to use the below statement to use the Nested IF statement in Power Query in Power BI without getting Token error like the following:

if [Start Date] > DateTime.Date then "Started" else if [End Date] <= DateTime.Date then "Finished" else "Not measured"

Nested IF statement in Power BI Power Query

Read also Power BI: Custom Column Vs Calculated Column

by 24 25 33
0 0
Thanks a lot for this great explanation
If you don’t ask, the answer is always NO!
...