cancel
Showing results for 
Search instead for 
Did you mean: 
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

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

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.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

@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

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

@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!

View solution in original post

Thanks for sharing.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

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

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

@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...

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.