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
Hi BA_Pete
Thank you so much that worked, I have posted my code as I am not getting the "Future Booked" result for greater than today but everything else is working perfectly now.
Kara
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
- KaraWilson4 years agoFrequent Visitor
Thanks BA_Pete ughh so new to this, you're right I had in one of the hundreds of times I tried to rewrite it changed the first < to a >!
After years of using excel and very very new to Power BI, managing DAX coding quite well M coding absolutely threw me!
Your M code worked a treat and I can now investigate where I was going wrong for my own understanding.
Many thanks for your continued support. Kara
- BA_Pete4 years agoSuper User
No worries Kara, happy to help.
Best of luck with your future M learning! 🙂
Pete