Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hello all,
I've a syntax issue, it returns me "THEN syntax is incorrect"
My code :
Has someone an idea to help me to understand my mistake ? Thanks,
Solved! Go to Solution.
Hi @PierreM52
Here's your if then else translated into M for Power Query
I've also created a PBIX file and an Excel Workbook with dummy data showing how this works.
#"Added Custom" = Table.AddColumn(PreviousStepName, "Custom", each
if
(Time.Hour([Debut]) >= 5 and Time.Hour([Debut]) < 13 and Date.DayOfWeek([Jour], Day.Monday) <> 5) then "Matin"
else if
(Time.Hour([Debut]) >= 3 and Time.Hour([Debut]) < 21 and Date.DayOfWeek([Jour], Day.Monday) <> 5) then "Après-midi"
else if
Date.DayOfWeek([Jour], Day.Monday) <> 5 then "Nuit"
else if
(Time.Hour([Debut]) >= 5 and Time.Hour([Debut]) < 11 and Date.DayOfWeek([Jour], Day.Monday) = 5) then "Matin"
else if
(Time.Hour([Debut]) >= 11 and Time.Hour([Debut]) < 17 and Date.DayOfWeek([Jour], Day.Monday) = 5) then "Après-midi"
else "Nuit")
Phil
If I answered your question please mark my post as the solution.
If you liked my answer click on the Thumbs Up icon.
Proud to be a Super User!
Hi @PierreM52
Here's your if then else translated into M for Power Query
I've also created a PBIX file and an Excel Workbook with dummy data showing how this works.
#"Added Custom" = Table.AddColumn(PreviousStepName, "Custom", each
if
(Time.Hour([Debut]) >= 5 and Time.Hour([Debut]) < 13 and Date.DayOfWeek([Jour], Day.Monday) <> 5) then "Matin"
else if
(Time.Hour([Debut]) >= 3 and Time.Hour([Debut]) < 21 and Date.DayOfWeek([Jour], Day.Monday) <> 5) then "Après-midi"
else if
Date.DayOfWeek([Jour], Day.Monday) <> 5 then "Nuit"
else if
(Time.Hour([Debut]) >= 5 and Time.Hour([Debut]) < 11 and Date.DayOfWeek([Jour], Day.Monday) = 5) then "Matin"
else if
(Time.Hour([Debut]) >= 11 and Time.Hour([Debut]) < 17 and Date.DayOfWeek([Jour], Day.Monday) = 5) then "Après-midi"
else "Nuit")
Phil
If I answered your question please mark my post as the solution.
If you liked my answer click on the Thumbs Up icon.
Proud to be a Super User!
Are you trying this in Power Query or DAX ?
________________________
If my answer was helpful, please consider Accept it as the solution to help the other members find it
Click on the Thumbs-Up icon if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
The syntax is wrong if it DAX. You don't enter THEN and ELSE,
Refer to this article: https://docs.microsoft.com/en-us/dax/if-function-dax
________________________
If my answer was helpful, please consider Accept it as the solution to help the other members find it
Click on the Thumbs-Up icon if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
You need use and instead of && also, all lower case
Refer to: https://docs.microsoft.com/en-us/powerquery-m/m-spec-conditionals
________________________
If my answer was helpful, please consider Accept it as the solution to help the other members find it
Click on the Thumbs-Up icon if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 5 | |
| 5 | |
| 4 |