Forum Discussion
Durbslaw
4 years agoHelper I
conditional datediff
Hi, I have 2 columns Period [YearMonth] which is a date filter and MovementSnapshot[AppointmentDatekey]. I would like a measure to datediff the Month if MovementSnapshot[AppointmentDatekey] is n...
- 4 years ago
Durbslaw
Please try this as a measureNewColumn = IF ( 'MovementSnapshot'[AppointmentDateKey] <> BLANK () && 'MovementSnapshot'[AppointmentDateKey] <> -1, VAR CurrentMovement = MAX ( 'MovementSnapshot'[AppointmentDateKey] ) VAR CurrentPeriod = MAX ( 'Period'[YearMonth] ) VAR MovementYear = VALUE ( LEFT ( CurrentMovement, 4 ) ) VAR MovementMonth = VALUE ( MID ( CurrentMovement, 5, 2 ) ) VAR PeriodYear = VALUE ( LEFT ( CurrentPeriod, 4 ) ) VAR PeriodMonth = VALUE ( RIGHT ( CurrentPeriod, 2 ) ) RETURN ( MovementYear - PeriodYear ) * 12 + MovementMonth - PeriodMonth ) - 4 years ago
Durbslaw
Sorry my mistake. Please tryNewColumn = VAR CurrentMovement = MAX ( 'MovementSnapshot'[AppointmentDateKey] ) VAR CurrentPeriod = MAX ( 'Period'[YearMonth] ) VAR MovementYear = VALUE ( LEFT ( CurrentMovement, 4 ) ) VAR MovementMonth = VALUE ( MID ( CurrentMovement, 5, 2 ) ) VAR PeriodYear = VALUE ( LEFT ( CurrentPeriod, 4 ) ) VAR PeriodMonth = VALUE ( RIGHT ( CurrentPeriod, 2 ) ) RETURN IF ( CurrentMovement <> BLANK () && CurrentMovement <> -1, ( MovementYear - PeriodYear ) * 12 + MovementMonth - PeriodMonth )