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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sujitjena
Resolver I
Resolver I

How to calculate last year QTD and link to slicer

Hi,

 

I am trying to create a slicer that can switch between MTD, QTD and YTD for all metrics. However, I am stuck at how to get QTD for Last year. Basically i want to show (Current yr QTD-Last year QTD)/Last Yr QTD -1 as a percentage.

I have the measures for YTD and once i have QTD and MTD as well, then how do i make the selection work for all the three (MTD,YTD and QTD) as shown in the picture below.

MTD QTD YTD slicer.PNG

1 ACCEPTED SOLUTION

@amitchandak : I think i found a way to calculate Fiscal Quarter. The below formula works great.

 

QTD

FQTD = CALCULATE (

[Sales total],

FILTER (

ALL ( 'Dates' ),

'Dates'[Fin Year] = VALUES(Dates[Fin Year])

&& 'Dates'[Quarter] = VALUES ( 'Dates'[Quarter] )

&& 'Dates'[Date] <= MAX ( 'Dates'[Date])

))

LYQTD

CALCULATE (FQTD, sameperiodlastyear(Dates[Date])

 

Thanks for your help!

View solution in original post

13 REPLIES 13
amitchandak
Super User
Super User

These are formulas you can use.

 

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date Filer],-1,MONTH))))
last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date Filer],-12,MONTH))))

MTD (Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR('Date'[Date Filer])))
MTD (Last Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR(dateadd('Date'[Date Filer],-12,MONTH),"8/31")))


QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(('Date'[Date Filer])))

Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date Filer],-1,QUARTER)))
Next QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date Filer],1,QUARTER)))

Last year same QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date Filer],-1,Year)))

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date Filer])))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date Filer],-1,Year)))

Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-3,MONTH))  

 

 

Dynamic Selection
https://community.powerbi.com/t5/Desktop/Dynamic-Metrics-Selection/td-p/605838
https://community.powerbi.com/t5/Desktop/Dynamic-measure-values-based-on-slicer-selection/td-p/41731...
https://community.powerbi.com/t5/Desktop/How-to-display-different-measures-using-a-selector/td-p/131...

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak : I tried the formula for last year QTD but it doesnt work. the below formula doesnt return any value.

Last year same QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date Filer],-1,Year)))

Not sure if i missed anything.

When you do not view it by time or choose a date. The default date is the end date of the calendar.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak : oh ok. Got it. Thanks!

Now, how do i connect the slicer (MTD/QTD/YTD) to toggle according to the selection?

for starters - i have a separate table for all three (MTD/QTD/YTD).

@amitchandak : I got the formula now but the problem is it doesnt follow the fiscal calendar. Is there a way around this?

Qtr name is just a display. But for both datesytd and totalytd, you should be able to give year-end date.

https://docs.microsoft.com/en-us/dax/datesytd-function-dax

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak : Well YTD works great but the QTD is where i am stuck. I have shared the PBIX file the below link. Please see 2018 onwards, QTD seems to calculate calendar quarter and not Fiscal Quarter. Is there a way to fix this?

 

https://www.dropbox.com/s/e7bdihgnmhiizt0/PBIX%20View.pbix?dl=0

 

@amitchandak : I think i found a way to calculate Fiscal Quarter. The below formula works great.

 

QTD

FQTD = CALCULATE (

[Sales total],

FILTER (

ALL ( 'Dates' ),

'Dates'[Fin Year] = VALUES(Dates[Fin Year])

&& 'Dates'[Quarter] = VALUES ( 'Dates'[Quarter] )

&& 'Dates'[Date] <= MAX ( 'Dates'[Date])

))

LYQTD

CALCULATE (FQTD, sameperiodlastyear(Dates[Date])

 

Thanks for your help!

Thanks for sharing.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

In my case 'Date' is calendar table marked as date and [Date Filer] is joined with sales date.  And all the dates in the calendar table cover complete date ranges of sales.

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak : Yes i have the Dates table in place and its connected to the fact tables. Although my "Quarter" column is a custom column in dates table and the fact tables. Hope that isn't a problem.

To help you further I need pbix file. If possible please share a sample pbix file after removing sensitive information.Thanks.

My Recent Blog -

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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