Forum Discussion
YTD Slicer
Hello,
I am trying to create a YTD/QTD/MTD slicer but I am encountering an issue.
First I create a Table Selection with only dates column that links to my Calendar Table ( Bi Directional Mode)
Then I am trying to add a new Measure in the Selection Table as follows
- Anonymous4 years ago
Hi VeemalS ,
If you want to change your measure result by slicer, I suggest you can try calculation group by tabular.
For reference: Creating Calculation Groups in Power BI Desktop
From your screenshot, I see that there are different months in same year. Do you want all month in 2021 show same result when you select YTD? And Apr/May/Jun show same results in Qtr2, Jul show results in Qtr3, when you select QTD? I am confused about the rates, what is the calculation logic of thems?
Please share a sample file with us and show us the result you want by screenshot.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
6 Replies
- amitchandak
Super User
VeemalS , Please use Time intellignce with date table, ine directional join
For measure slicer refer
measure slicer
https://www.youtube.com/watch?v=b9352Vxuj-M
https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/500115
https://radacad.com/change-the-column-or-measure-value-in-a-power-bi-visual-by-selection-of-the-slicer-parameter-table-pattern
https://www.youtube.com/watch?v=vlnx7QUVYMEcalculation groups
https://www.sqlbi.com/blog/marco/2020/07/15/creating-calculation-groups-in-power-bi-desktop/QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(('Date'[Date])))
Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))- VeemalS
Helper I
Thanks for the solution. But with this one I will have to create mutiple measures for each time periods which is somthing not acceptable by the user. In fact I was able to resolve same as I had to switch to creation of New Table iso a Measure.
- VeemalS
Helper I
This is the new DAX code:
CustomSelect =VAR PaxRevDate = MAX('Pax Revenue'[UpliftDate])--Today()VAR Dates_YTD = Calculate (STARTOFYEAR('Time'[PeriodDate]), YEAR('Time'[PeriodDate]) = YEAR(PaxRevDate))--DATESYTD('Pax Revenue'[UpliftDate])VAR Dates_QTD = Calculate (STARTOFQUARTER('Time'[PeriodDate]),YEAR('Time'[PeriodDate]) = YEAR(PaxRevDate), QUARTER('Time'[PeriodDate]) = QUARTER(PaxRevDate))--DATESQTD( 'Pax Revenue'[UpliftDate])VAR Dates_MTD = Calculate (STARTOFQUARTER('Time'[PeriodDate]),YEAR('Time'[PeriodDate]) = YEAR(PaxRevDate), MONTH('Time'[PeriodDate]) = MONTH(PaxRevDate))--DATESMTD('Pax Revenue'[UpliftDate])RETURNvar FinalResult =UNION(ADDCOLUMNS(CALENDAR(Dates_YTD,PaxRevDate),"Selection","YTD"),ADDCOLUMNS(CALENDAR(Dates_QTD,PaxRevDate),"Selection","QTD"),ADDCOLUMNS(CALENDAR(Dates_MTD,PaxRevDate),"Selection","MTD")) return FinalResultHowever does not solve all the problems as I am not able to filter on LY Measures. So for instance if I have a measure that has been filtered by SAMEPERIODLASTYEAR, the report does not bring any value. Same for DateAdd.Any suggestion?ThanksVeemal - VeemalS
Helper I
- AnonymousNot applicable
Hi VeemalS ,
If you want to change your measure result by slicer, I suggest you can try calculation group by tabular.
For reference: Creating Calculation Groups in Power BI Desktop
From your screenshot, I see that there are different months in same year. Do you want all month in 2021 show same result when you select YTD? And Apr/May/Jun show same results in Qtr2, Jul show results in Qtr3, when you select QTD? I am confused about the rates, what is the calculation logic of thems?
Please share a sample file with us and show us the result you want by screenshot.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- VeemalS
Helper I
Hello,
Thanks. The Calculation groups ( With Tabular Editor) resolved my issue.
Brgds
Veemal