Forum Discussion
Filter year/quarter in a calculation
I want to filter the current years quarter in a calculation.
Currently I am using two filters like this:
A02 = CALCULATE(A01, FILTER(PT, [PTDate].[Year]=YEAR([ActualDate])), FILTER( PT, [PTDate].[QuarterNo]=QUARTER([ActualDate] )))
Is there a better way to catch the year and quarter reference at once?
dp32 That looks reasonable to me. Quarters are a pain! 🙂
4 Replies
- amitchandak
Super User
dp32 , if you can use time intelligence that would be best . With a date table
QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(('Date'[Date])))
Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))another way is qtr rank/ with Qtr/date table
Qtr Rank = RANKX(all('Date'),'Date'[Qtr Start date],,ASC,Dense)
This Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])))
Last Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])-1))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
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184
Appreciate your Kudos. - Greg_Deckler
Community Champion
dp32 That looks reasonable to me. Quarters are a pain! 🙂
- dp32
Helper I
Thank you both.
Time logic will not work, so I will stay with the current version.
Quarters are indeed a pain, but not the only one :-).
- v-xicai
Community Support
Hi dp32 ,
You may change your code like below:
A02 = CALCULATE ( [A01], FILTER ( PT, [PTDate].[Year] = YEAR ( [ActualDate] ) && [PTDate].[QuarterNo] = QUARTER ( [ActualDate] ) ) )Best Regards,
Amy
Community Support Team _ Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.