Forum Discussion
Calculate previous quarter based on other date indicator
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,
3
)
// 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.
https://community.fabric.microsoft.com/t5/Desktop/Previous-Quarter-Calculation/td-p/1344347