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 not blank or -1.
I have...
NA DateDiff = IF(NOT('MovementSnapshot'[AppointmentDateKey])= -1 && NOT(ISBLANK('MovementSnapshot'[AppointmentDateKey])) ,DATEDIFF(SELECTEDVALUE('Period'[YearMonth]),MAX('MovementSnapshot'[AppointmentDatekey]),MONTH))
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 )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 )
11 Replies
- tamerj1Community Champion
How does the data in each column look like?
- DurbslawHelper I
- tamerj1Community Champion
Hi Durbslaw
Please use the following formulaNewColumn = 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 )
- PC2790Community Champion
- tamerj1Community Champion
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 )- DurbslawHelper I
syntax error...
- tamerj1Community Champion
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 )