Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Having Trouble in Power Query

@ links to members, content

 

I am new to Power Query.  I tried to add this column  I am getting error message "Token Literal expected".  Here is my DAX in power query 

= Table.AddColumn(#"Changed Type1", "CalDueFormat", each if [Calibration Due] > Date.From(DateTime.LocalNow()) & if [Calibration Due] < Date.From(DateTime.LocalNow()+ 90 then "Due in 90 Days" else if [Calibration Due] > Date.From(DateTime.LocalNow()) then |
"In Calibration" else "OverDue")

 

My two condition is not being evaluated.  The results only returns "OverDue" 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use this please

= Table.AddColumn(#"Changed Type1", "CalDueFormat", each if [Calibration Due] <= Date.From(DateTime.LocalNow()) then "Overdue" else if [Calibration Due] <= Date.From(Date.AddDays(DateTime.LocalNow(),90)) then "Due in 90 Days"
else "In Calibration")

 

View solution in original post

5 REPLIES 5
mussaenda
Community Champion
Community Champion

you think you should use "and" instead of "&"?

or you should use "or" instead of "&".

 

Try to play with these until you get your desired result.

 

If you need more help,

provide a sample data.

 

Thanks

Anonymous
Not applicable

the issue is the formula is not reading the first condition I do have some rows that meet that first condition.  I am having trouble adding 90 days to the Date.AddDays(DateTime.LocalNow(),90). I am getting error message "Token Literal Expected"

 

 

= Table.AddColumn(#"Changed Type1", "CalDueFormat", each if [Calibration Due] > Date.From(DateTime.LocalNow()) and if [Calibration Due] < Date.AddDays(DateTime.LocalNow(),90) then "Due in 90 Days" else if [Calibration Due] > Date.From(DateTime.LocalNow()) then
"In Calibration" else "OverDue")

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use below formula

= Table.AddColumn(#"Changed Type1", "CalDueFormat", each if [Calibration Due] <= Date.From(DateTime.LocalNow()) then "In Calibration" else if [Calibration Due] <= Date.From(Date.AddDays(DateTime.LocalNow(),90)) then "Due in 90 Days"
else "Overdue")
Anonymous
Not applicable

Thank you for adjusting the formula, it is returning the expected text string but applying color coding to wrong columns.  Where it is saying "In Calibration"  it should have "OverDue" and where it is "In Calibration" it should say "OverDue". 

 

This is my color measure

CalColor = SWITCH(
SELECTEDVALUE('DL - Tools, Test Equipment, and Tech Gear'[CalDueFormat]),
"OverDue", "Red",
"Due in 90 Days", "Yellow",
"In Calibration", "Green"
)

 

evester_0-1649480357726.png

I really appreciate your help on this.  Getting close to the expected solution. 

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use this please

= Table.AddColumn(#"Changed Type1", "CalDueFormat", each if [Calibration Due] <= Date.From(DateTime.LocalNow()) then "Overdue" else if [Calibration Due] <= Date.From(Date.AddDays(DateTime.LocalNow(),90)) then "Due in 90 Days"
else "In Calibration")

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.