Forum Discussion

TomLU123's avatar
TomLU123
Icon for Helper III rankHelper III
7 years ago
Solved

[Seek help] How to calculate the value difference on two dates?

Hi Expert,    I have a table like below which shows the actice workers as of two dates. I would like to create a measure to calculate the difference of headcount between these two dates.  Effe...
  • AlB's avatar
    7 years ago

    Hi TomLU123 

    Try this measure in a card visual. You can change the dates of interest in the code. This could also be done through slicers.

     

     

    Measure =
    VAR _Date1 = DATE ( 2019, 01, 01 )
    VAR _Date2 = DATE ( 2019, 03, 18 )
    VAR _HeadCountDate1 =
        CALCULATE (
            DISTINCTCOUNT ( Table1[Employee] ),
            Table1[Effective Date] = _Date1
        )
    VAR _HeadCountDate2 =
        CALCULATE (
            DISTINCTCOUNT ( Table1[Employee] ),
            Table1[Effective Date] = _Date2
        )
    RETURN
        _HeadCountDate2 - _HeadCountDate1

     

  • AlB's avatar
    AlB
    7 years ago

    TomLU123 

    Basically what you're saying, if I'm not mistaken, is that you want the earliest and latest dates selected in the slicers, so  just taking the MIN and MAX should suffice. Note it is also necessary to update the filter argument  in the CALCULATEs; the logic is still the same but MIN and MAX are not allowed in the simplified syntax so we have t use FILTER. Please consider kudoing the posts if they are of help.  Table1[Effective Date] is what you'd need on the slicer.

     

    Cheers 

     

    Measure_v2 =
    VAR _Date1 = MIN ( Table1[Effective Date] )
    VAR _Date2 = MAX ( Table1[Effective Date] )
    VAR _HeadCountDate1 =
        CALCULATE (
            DISTINCTCOUNT ( Table1[Employee] ),
            FILTER ( ALL ( Table1[Effective Date] ), Table1[Effective Date] = _Date1 )
        )
    VAR _HeadCountDate2 =
        CALCULATE (
            DISTINCTCOUNT ( Table1[Employee] ),
            FILTER ( ALL ( Table1[Effective Date] ), Table1[Effective Date] = _Date2 )
        )
    RETURN
        _HeadCountDate2 - _HeadCountDate1