Forum Discussion
Trailing 12 month YOY Comparison
Hi All,
Firstly Ritaf1983 thank you for your solution!
And Jidnyasa2904 ,I think the meaning of your DAX code is to generate a Time Interval Selector for selecting different time ranges in Power BI. The function of this time interval selector is to help the user quickly switch between different time perspectives to view the data, right?
In our attempt, we applied a similar approach to help you achieve this requirement, first we create a new table to provide filtering to the user, and then we filter based on the data in the table on the basis of our Date Table Make sure that this value of yours is dynamic Hopefully, this will help you with your question!
TimePeriodChoices =
DATATABLE(
"TimePeriod", STRING,
{
{"Year to Date"},
{"Month to Date"},
{"Week to Date"},
{"Trailing 12 Months"}
}
)Dynamic Total Sales =
VAR SelectedPeriod = SELECTEDVALUE(TimePeriodChoices[TimePeriod], "Year to Date")
VAR TodayDate = TODAY()
VAR YearStart = DATE(YEAR(TodayDate), 1, 1)
VAR MonthStart = DATE(YEAR(TodayDate), MONTH(TodayDate), 1)
VAR WeekStart = TodayDate - WEEKDAY(TodayDate, 2) + 1
VAR Trailing12MonthsStart = EDATE(TodayDate, -12)
RETURN
SWITCH(
SelectedPeriod,
"Year to Date", CALCULATE(SUM('Sales Table'[Sales]), 'Date Table'[Date] >= YearStart && 'Date Table'[Date] <= TodayDate),
"Month to Date", CALCULATE(SUM('Sales Table'[Sales]), 'Date Table'[Date] >= MonthStart && 'Date Table'[Date] <= TodayDate),
"Week to Date", CALCULATE(SUM('Sales Table'[Sales]), 'Date Table'[Date] >= WeekStart && 'Date Table'[Date] <= TodayDate),
"Trailing 12 Months", CALCULATE(SUM('Sales Table'[Sales]), 'Date Table'[Date] >= Trailing12MonthsStart && 'Date Table'[Date] <= TodayDate),
BLANK()
)
If you have more recent questions, you can contact us at any time, we will be the first time to reply to you after receiving your message, looking forward to your reply!
Hope it helps!
Best regards,
Community Support Team_ Tom Shen
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
- Jidnyasa29041 year ago
Helper I
Anonymous I have made some changes to the file you have attached. But I am unable to upload it.
- Anonymous1 year agoNot applicable
Hi Jidnyasa2904 ,
You can take your modified pbix file, store it in the cloud and send me the link so I can understand your needs better and give you an accurate solution!
How to provide sample data in the Power BI Forum - Microsoft Fabric Community
Looking forward to your reply!
- Jidnyasa29041 year ago
Helper I
https://drive.google.com/file/d/1lUuzfjh8pug8_mmQ5aGZAMR5-WmgXyYP/view?usp=drive_link
I have made changes to the file.