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 )
PC2790
4 years agoCommunity Champion
- Durbslaw4 years agoHelper I
error
- PC27904 years agoCommunity Champion
This will not work as a measure. Try having a calculated column. Something like:
Column = if(Not(ISBLANK('MovementSnapshot'[AppointmentDateKey])) || 'MovementSnapshot'[AppointmentDateKey] <> -1,DATEDIFF('Period'[YearMonth],'MovementSnapshot'[AppointmentDateKey],MONTH))Also, another thing to make sure is the two values you are using are of date datatype.Otherwise it won't work like this.