Forum Discussion
Automatically add months based on thrill through filter
- 6 years ago
Hi Yubo ,
Please check if the workaround below is working.
1. Create another Calendar Table without relationship in your scenario.
2. Create Year and Month slicers from the Calendar Table without relationship.
3. Change your YTD measure like so.
ActYTD 2 = VAR SelectedYear = SELECTEDVALUE ( 'Calendar without relationship'[Year] ) VAR SelectedMonth = SELECTEDVALUE ( 'Calendar without relationship'[Month] ) VAR StartDate = IF ( SelectedMonth IN { 1, 2, 3 }, DATE ( SelectedYear - 1, 4, 1 ), DATE ( SelectedYear, 4, 1 ) ) VAR EndDate = DATE ( SelectedYear, SelectedMonth + 1, 1 ) RETURN CALCULATE ( SUM ( 'Table'[Profit] ), FILTER ( ALL ( 'Calendar with relationship' ), 'Calendar with relationship'[Date] >= StartDate && 'Calendar with relationship'[Date] < EndDate ) )4. Just put the "Measure" in the attached PBIX file in all visuals you want to show 3 months.
Measure = VAR CurrentDate = MAX ( 'Table'[Date] ) VAR SelectedYear = SELECTEDVALUE ( 'Calendar without relationship'[Year] ) VAR SelectedMonth = SELECTEDVALUE ( 'Calendar without relationship'[Month] ) VAR SelectedFirstDayOfNextMonth = IF ( SelectedMonth = 12, DATE ( SelectedYear + 1, 1, 1 ), DATE ( SelectedYear, SelectedMonth + 1, 1 ) ) VAR SelectedFirstDayOfLastPirorLastMonth = IF ( SelectedMonth = 1 || SelectedMonth = 2, DATE ( SelectedYear - 1, SelectedMonth + 10, 1 ), DATE ( SelectedYear, SelectedMonth - 2, 1 ) ) RETURN IF ( SelectedYear = BLANK () || SelectedMonth = BLANK (), 1, IF ( CurrentDate >= SelectedFirstDayOfLastPirorLastMonth && CurrentDate < SelectedFirstDayOfNextMonth, 1 ) )Then you can get this:
For more details, please check the attached PBIX file.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Yubo ,
Please check if the workaround below is working.
1. Create another Calendar Table without relationship in your scenario.
2. Create Year and Month slicers from the Calendar Table without relationship.
3. Change your YTD measure like so.
ActYTD 2 =
VAR SelectedYear =
SELECTEDVALUE ( 'Calendar without relationship'[Year] )
VAR SelectedMonth =
SELECTEDVALUE ( 'Calendar without relationship'[Month] )
VAR StartDate =
IF (
SelectedMonth IN { 1, 2, 3 },
DATE ( SelectedYear - 1, 4, 1 ),
DATE ( SelectedYear, 4, 1 )
)
VAR EndDate =
DATE ( SelectedYear, SelectedMonth + 1, 1 )
RETURN
CALCULATE (
SUM ( 'Table'[Profit] ),
FILTER (
ALL ( 'Calendar with relationship' ),
'Calendar with relationship'[Date] >= StartDate
&& 'Calendar with relationship'[Date] < EndDate
)
)
4. Just put the "Measure" in the attached PBIX file in all visuals you want to show 3 months.
Measure =
VAR CurrentDate =
MAX ( 'Table'[Date] )
VAR SelectedYear =
SELECTEDVALUE ( 'Calendar without relationship'[Year] )
VAR SelectedMonth =
SELECTEDVALUE ( 'Calendar without relationship'[Month] )
VAR SelectedFirstDayOfNextMonth =
IF (
SelectedMonth = 12,
DATE ( SelectedYear + 1, 1, 1 ),
DATE ( SelectedYear, SelectedMonth + 1, 1 )
)
VAR SelectedFirstDayOfLastPirorLastMonth =
IF (
SelectedMonth = 1
|| SelectedMonth = 2,
DATE ( SelectedYear - 1, SelectedMonth + 10, 1 ),
DATE ( SelectedYear, SelectedMonth - 2, 1 )
)
RETURN
IF (
SelectedYear = BLANK ()
|| SelectedMonth = BLANK (),
1,
IF (
CurrentDate >= SelectedFirstDayOfLastPirorLastMonth
&& CurrentDate < SelectedFirstDayOfNextMonth,
1
)
)
Then you can get this:
For more details, please check the attached PBIX file.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Icey,
Good News - It worked like a charm. 😱
Many thanks for your supports!!
All the best,
YuBo