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,
It works perfectly if only two levels of drill through -page1 & page2.
But I have 4 levels of drill through-page1,2,3 &4, the first 3 levels have fiscal Year and month filters, the last page is details.
Tried to make a connotation between the filters.
if in page3, I put 4 filters (hide all of them) - FiscalYear, FiscalMonth (the values carried from level2), Year ,Month in without relationship calendar. In the measure (ActYTD), to pass the values from FiscalYear/fiscalmonth to Year/month, then use the ways you did. The formula I tried below is not working, not know how to write the code.
Do you think it will be a way? Or any ideas for 4 levels drill through?
ActYTD 2 =
VAR SelectedYear =
IF (SELECTEDVALUE ( 'Calendar'[FiscalYear])<>0,
SELECTEDVALUE ( 'Calendar without relationship'[Year] )=SELECTEDVALUE( 'Calendar'[FiscalYear] ))
//SELECTEDVALUE ( 'Calendar'[FiscalYear])
VAR SelectedMonth =
if (SELECTEDVALUE ( 'Calendar'[FiscalMonth])<>0,
SELECTEDVALUE ( 'Calendar without relationship'[Month] )=SELECTEDVALUE ( 'Calendar'[FiscalMonth]))
//SELECTEDVALUE ( 'Calendar'[FiscalMonth])
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([Actuals],DATESYTD('Calendar'[Date],"31/3"),
// VALUE([ActYTD]),
FILTER (
ALL ( GL ),
GL[GL Date] >= StartDate
&& GL[GL Date]< EndDate
)
)
Thank you so much Icey!! 🙏
YuBo