Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Helper IV
Helper IV

Calculate previous quarter based on other date indicator


I am struggling with calculating previous quarter based on some 'random' date column, not based on the 'mother' calendar date.
I know that all time inteligence works based on the calendar table, but the max date differs when report lvl filter is applyed.
I need to restrict the max date, based on the values_as_of_date from the different table.

I want to acheive something like below, but powerBi does not allow to put variable/ calculate/etc into PREVIOUSQUARTER.
I have also tried with dateadd and other date formulas but nothing really work for me.
Maybe someone here knows a work around for this ?

var maxdate =calculate(max(table[values_as_of_date]),all('Calendar'))

var lastq=calculate(ENDOFMONTH(PREVIOUSQUARTER(maxdate)))

Thanks in advance!

Super User
Super User

Hey, @Kopek 


here is an idea. 

First extract month and year from the max date then calculate the quarter. 


something like,


var maxdate = CALCULATE(MAX(table[values_as_of_date]), ALL('Calendar'))
var currentMonth = MONTH(maxdate)
var currentYear = YEAR(maxdate)

// Calculate the previous quarter's year and quarter number
var previousQuarterYear = IF(currentMonth <= 3, currentYear - 1, currentYear)
var previousQuarterNumber = SWITCH(TRUE(),
currentMonth <= 3, 4,
currentMonth <= 6, 1,
currentMonth <= 9, 2,

// Calculate the start and end dates of the previous quarter
var previousQuarterStart = DATE(previousQuarterYear, (previousQuarterNumber - 1) * 3 + 1, 1)
var previousQuarterEnd = EOMONTH(DATE(previousQuarterYear, previousQuarterNumber * 3, 1), -1)


return previousQuarterStart, previousQuarterEnd


this is an idea, you need to adjust the code. probably you need to calculate current quarter as well.


see that if this helps


Also, see this thread if that gives you any idea.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Hi @rubayatyasmin , thanks for suggestion.

I ended up doing it in powerquery 🙂

Thanks! 🙂

Helpful resources

PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors