Forum Discussion

marjoriefialek's avatar
5 years ago
Solved

Date comparison help

How can I compared these 2 dates.   org_chart_employees[term_date] is part of the table and it's a date column.  My DAX is: I set up meausure: VARTermed = CALCULATE(MIN('Calendar'[DATE]),ALL...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi,marjoriefialek 

    From your description, I have entered some sample data like the picture below:

     

    Calendar = calendar(date(2020,1,1),today())

     

     

    VARTermed = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar'))

     

     

    VARTermedFlag = IF(org_chart_employees[term_date] >= [VARTermed], "yes", "no")  

     

     

     

    VARTermedFlag = IF(org_chart_employees[term_date] >= [VARTermed], "yes", "no")  always return Yes.

    Because Measure is a dynamic aggregated value, in the VARTermed = CALCULATE(MIN('Calendar'[DATE]),ALLSELECTED('Calendar')) scenario, the minimum value of ‘calendar will always be returned.

     

    Even if they look similar, there is a big difference between calculated columns and measures.

    The value of a calculated column is computed during data refresh and uses the current row as a context; it does not depend on user interaction in the report.

    A measure operates on aggregations of data defined by the current context, which depends on the filter applied in the report – such as slicer, rows, and columns selection in a pivot table, or axes and filters applied to a chart.

     

    I would like to suggest you take a look at below blog which told about difference between calculated column and measure:

    Calculated Columns and Measures in DAX

     

    For a better way to do the Date comparison, you can try this:

    Measure = IF(MAX(org_chart_employees[Term_date]) >= [VARTermed], "yes", "no")  

     

     

     

     

    Here is the demo , please try it:

    https://qiuyunus-my.sharepoint.com/:u:/g/personal/linli_qiuyunus_onmicrosoft_com/EYjKO865mD5GpX3aZv3TY9oBOGy_OhYA0RpBzSQ79UF9ow?e=1Ka0XP

     

    Hope it helps.

     

    Best Regards,

    Caitlyn Yan

     

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