Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Kgi_jrd
Regular Visitor

Dynamic period comparison based on date selection

I'm building PBI dashboards for a client who is migrating from another tool (Targit). Their current system has pretty robust dynamic date capabilities, allowing you to use a calendar selector to alter the 'as of' date on the dashboards. Meaning if I were viewing a dashboard that had measures for sales and goals (derived from different fact tables), the reporting tool had built in comparisons for YTD vs PY YTD that I could apply to the visual. That visual would default to today's date, but I could drag that date back to any point in history. If I moved the date back to 12/31/23, I would then be looking at 1/1/23-12/31/23 vs 1/1/22-12/31/22. If I moved the date back to 6/30/23, then the comparison period would become 1/1/23-6/30/23 vs 1/1/22-6/30/22.
Their team has gotten used to this dynamic date flexibility and I'm trying to figure out how to replicate it, or get close, in PBI. We're working with a model being fed by a tabular cube, so most of the DAX is done in Visual Studio. I added current day/month/year offset values in my date table which I've used to build out YTD and PYTD measures in necessary tables, but that doesn't give me the ability to look back on demand.
I've tried using selectedyear and selectedyear -1 measures to add a date slicer option, but then I lose my ability to get that true yoy comparison when current year is incomplete and previous year is complete.
Any tips on how to alter the 'as-of' date relative to all dynamic measures?

2 REPLIES 2
amitchandak
Super User
Super User

@Kgi_jrd , You can use Preselected Slicer, to have selected value as today using measure-

amitchandak_0-1706855837260.png

 

 

With standard slicer you have to do work around with table
Is Today = if('Date'[Date]=TODAY(),"Today",[Date]&"")


Default Date Today/ This Month / This Year: https://www.youtube.com/watch?v=hfn05preQYA

 

Then you can use Time Intelligence

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"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),previousyear('Date'[Date]))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]))
week Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-364,DAY))


Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510
Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I believe I've achieved something similar with day/month/year offset. Current value is 0, previous value is -1, etc. However, I've never been able to get the native time intelligence to work in visual studio...my formulas always end up blank. It's the same table used in the old olap cube that was powering the old reporting tool and the native time intelligence in that tool worked fine.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.