Forum Discussion
Convert DAX to M Code
- 4 years ago
You're not getting your 'Future Booked' outputs because your first condition is negating it.
Your first condition reads as:
if [interviewDate] is yesterday or later then 'No result'
Your 'Future Booked' condition reads as:
if [interviewDate] is today or later then "Future Booked"
Can you see how your second condition has already been evaluated as part of the first condition?
The calculation that you posted right at the start of this thread had the first condition as:
if [interviewResult] is blank and [interviewDate] was yesterday or earlier then "No result". It looks like this condition has changed in the evolution.
Here's your original (presumably working as required) DAX calculation, properly converted to M code (because I'm nice like that):
let Date.Today = Date.From(DateTime.LocalNow()) in if [InterviewDate] = null then null else if [InterviewResult] = null and [InterviewDate] <= Date.AddDays(Date.Today, -1) then "No Result" else if [InterviewResult] = null and [InterviewDate] >= Date.Today then "Future Booked" else if [InterviewResult] = "Attended" then "No Result" else if [InterviewResult] = "Failed to Attend" then "FTA" else [InterviewResult]Pete
Since M-code is case sensitive, did you try with null intead of Null and "if " (with space) instead of "if"?
- KaraWilson4 years agoFrequent Visitor
Hi Jakinta
No I hadn't tried that but have done so now and it is still not working, the error I am getting is 'Token Else Expected' after the row that says
if[InterviewResult]="Pass"
then "Pass"
else.....
The first occurance of "Pass" is also underlined in red as to show that's where the error is.
Thanks
- Jakinta4 years agoSolution Sage
That means you are missing else after "Pass".
You have to follow nested if statements pattern.if ....
then ...
else if ....
then ...
else if ....
then ...
else .... (at the end)