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 )
Durbslaw
4 years agoHelper I
tamerj1
4 years agoCommunity Champion
Hi Durbslaw
Please use the following formula
NewColumn =
IF (
'MovementSnapshot'[AppointmentDateKey] <> BLANK ()
&& 'MovementSnapshot'[AppointmentDateKey] <> -1,
VAR MovementYear =
VALUE ( LEFT ( 'MovementSnapshot'[AppointmentDateKey], 4 ) )
VAR MovementMonth =
VALUE ( MID ( 'MovementSnapshot'[AppointmentDateKey], 4, 2 ) )
VAR PeriodYear =
VALUE ( LEFT ( 'Period'[YearMonth], 4 ) )
VAR PeriodMonth =
VALUE ( RIGHT ( 'Period'[YearMonth], 2 ) )
RETURN
( MovementYear - PeriodYear ) * 12 + MovementMonth - PeriodMonth
)- Durbslaw4 years agoHelper I
Aplogies for the non clarity, I need a measure as I am using SSAS as a source and cannot create columns.