Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Convert Calculated Column to DAX measure

Hi All,

 

I want to convert the below calculated column into a DAX measure. 

 

 

Please help me in writing a measure for this.

 

Thanks!

 

Best,

Hammad

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data. 

    (2)Please check that the [Date Closed(Text)] column is in text format and rendered in "mm/dd/yyyy" format.

    (3)We can create a measure.

    Project Status = 
    VAR revenue_percent =
        MAX( 'Project Status'[Revenue Yet To Be Booked (%)] )
    VAR revenue_value =
        MAX(  'Project Status'[Project Status'[Revenue Yet To Be Booked ($)] )
    VAR date_value =
        MAX(  'Project Status'[Project Status'[Date Closed(Text)] )
    RETURN
    IF(
        revenue_percent <= 0.05
                || revenue_value < 5000
                || date_value <> "10/31/2022", 
            "CLOSED",
            "OPEN"
    )

    (3) Then the result is as follows.

    My PBIX file is as follows, please refer to.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data. 

    (2)Please check that the [Date Closed(Text)] column is in text format and rendered in "mm/dd/yyyy" format.

    (3)We can create a measure.

    Project Status = 
    VAR revenue_percent =
        MAX( 'Project Status'[Revenue Yet To Be Booked (%)] )
    VAR revenue_value =
        MAX(  'Project Status'[Project Status'[Revenue Yet To Be Booked ($)] )
    VAR date_value =
        MAX(  'Project Status'[Project Status'[Date Closed(Text)] )
    RETURN
    IF(
        revenue_percent <= 0.05
                || revenue_value < 5000
                || date_value <> "10/31/2022", 
            "CLOSED",
            "OPEN"
    )

    (3) Then the result is as follows.

    My PBIX file is as follows, please refer to.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

  • HI Anonymous ,

     

    Just writing the DAX measure on the fly, so if there are any syntax errors, apologies for that.

    You can write this as a DAX measure something like below:

    Project Status =
    VAR revenue_percent =
        SELECTEDVALUE ( 'Project Status'[Revenue Yet To Be Booked (%)] )
    VAR revenue_value =
        SELECTEDVALUE ( 'Project Status'[Revenue Yet To Be Booked ($)] )
    VAR date_value =
        SELECTEDVALUE ( 'Project Status'[Date Closed(Text)] )
    RETURN
        SWITCH (
            TRUE (),
            revenue_percent <= 0.05
                || revenue_value < 5000
                || date_value <> "10/31/2022", 
            "CLOSED",
            "OPEN"
        )
    

    See if this works.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Pragati11 

     

    Thanks for the measure. I tried checking the results vs calculated column. But both are showing different mapping - CLOSED / OPEN. Calculated column is correct though. For measure, everything is mapped as "CLOSED".

    It must be something related to CONTEXT - calculated column vs measure.

     

    Any solution this ? I read somewhere, we should use "CALCULATE" to change the context.

    • Pragati11's avatar
      Pragati11
      Super User

      Hi Anonymous ,

      Can you please share some sample data so that I can test the DAX measure? It's hard for me to say why it doesn't work without testing it as I don't have a view around the data in these columns.

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi All, please help!