cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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.

1 ACCEPTED SOLUTION
Resolver I

@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])

13 REPLIES 13
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))  ``````

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

Resolver I

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.

Super User

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

Resolver I

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

Super User

These links did not provide the info you need ??

Resolver I

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

Super User

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

Resolver I

@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

Resolver I

@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])

Super User

Thanks for sharing.

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

Resolver I

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

Super User

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

Announcements