Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
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...
Solved! Go to Solution.
@Durbslaw
Please try this as a measure
NewColumn =
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 try
NewColumn =
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
Please try this as a measure
NewColumn =
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
)
syntax error...
@Durbslaw
Sorry my mistake. Please try
NewColumn =
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
)
error
This will not work as a measure. Try having a calculated column. Something like:
The location of the closing bracket of not should be after the "1". But even though I don't believe this is a correct code. Please provide more details about your data.
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
)
Aplogies for the non clarity, I need a measure as I am using SSAS as a source and cannot create columns.
The Power BI Data Visualization World Championships is back! It's time to submit your entry.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 70 | |
| 55 | |
| 38 | |
| 28 | |
| 22 |
| User | Count |
|---|---|
| 133 | |
| 119 | |
| 54 | |
| 37 | |
| 31 |