Forum Discussion

KaraWilson's avatar
KaraWilson
Frequent Visitor
4 years ago
Solved

Convert DAX to M Code

Hi All   I am having some trouble converting DAX to M Code, I have data that I need to change the results on but then need to create a conditional column so am unable to use as a DAX column - I hav...
  • BA_Pete's avatar
    BA_Pete
    4 years ago

    KaraWilson ,

     

    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