Forum Discussion
TomLU123
Helper III
7 years ago[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...
- 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 - 7 years ago
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
AlB
Community Champion
7 years agoI hadn't had time.
Try this
Measure_v3 =
VAR _Date2 = MAX ( Table1[Effective Date] )
VAR _Date1 = CALCULATE ( MAX ( Table1[Effective Date] ), Table1[Effective Date] < _Date2 )
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