Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
BenCollins
New Member

Time Intelligence in Tabular Editor

I've created a time calculation period of QTD and Quarter in Tabular Editor.

I've created Quarter as

VAR SelectedQuarterStart = CALCULATE(MAX(DocumentDate[QuarterStart]), ALLSELECTED(DocumentDate[DayOfQuarter])) VAR QuarterStartAll = MAX(DocumentDate[QuarterStart]) VAR MaxDayOfQuarter = CALCULATE(MAX(DocumentDate[DayOfQuarter]), DocumentDate[QuarterStart] = QuarterStartAll) VAR MaxDayOfQuarterSelected = CALCULATE(MAX(DocumentDate[DayOfQuarter]), ALLSELECTED(DocumentDate), DocumentDate[QuarterStart] = QuarterStartAll) VAR Result = CALCULATE( SELECTEDMEASURE(), REMOVEFILTERS(DocumentDate), DocumentDate[QuarterStart] = SelectedQuarterStart, DocumentDate[DayOfQuarter] <= MaxDayOfQuarter ) RETURN Result


Then I've created a time calculation for 'Previous Quarter' like this

VAR _selperiod = SELECTEDVALUE ( 'Time Intelligence Periods'[Calculation Period], "Selected Range" ) VAR _StartDate = CALCULATE ( MIN ( DocumentDate[Date] )) VAR _EndDate = IF ( _selperiod = "QTD", MIN ( CALCULATE ( MAX ( DocumentDate[Date] ) ), MAX ( 'Refresh Date'[LastDateWithData] ) ), CALCULATE ( MAX(DocumentDate[QuarterEnd])) ) VAR _DaysSelected = CALCULATETABLE ( VALUES ( DocumentDate[Date] ), DATESBETWEEN ( DocumentDate[Date], _StartDate, _EndDate ) ) VAR _refperiod = IF ( _selperiod IN {"QTD", "Quarter"}, "Qtrs", BLANK() ) VAR _t = FILTER ( ADDCOLUMNS ( CALCULATETABLE ( DATEADD ( DocumentDate[Date], -3, MONTH ) ), "Range", "Qtrs" ), _refperiod = [range] ) VAR _value = SELECTEDMEASURE () VAR _prevvalue = CALCULATE ( SELECTEDMEASURE (), _t ) RETURN IF ( _selperiod IN {"FYTD", "Selected Range", "MTD", "Monthly" }, BLANK(), IF ( SELECTEDMEASURENAME () = "CF Dynamic Measure", BLANK(), _prevvalue ) )


The QTD works as expected. If I'm mid quater it will show the previous period from the start of the previous quarter up to the same day as my 'current period'
When I select Quarter, it still shows the same number of days from the previous quarter rather than going to the end of the quarter.

My MTD and Monthly calculations are built the same way and they work fine, I just can't work out why the Quarter calculation isn't working as I want it too

 

1 ACCEPTED SOLUTION
BenCollins
New Member

I've actually solved my own problem. Sorry for the inconvenience everyone, but if it's bugging anyone what it was it was because I had missed a  _DaysSelected from my ADDCOLUMNS section

ADDCOLUMNS ( CALCULATETABLE ( DATEADD ( DocumentDate[Date], -3, MONTH ),_DaysSelected ), "Range", "Qtrs" ),

 

View solution in original post

2 REPLIES 2
BenCollins
New Member

I've actually solved my own problem. Sorry for the inconvenience everyone, but if it's bugging anyone what it was it was because I had missed a  _DaysSelected from my ADDCOLUMNS section

ADDCOLUMNS ( CALCULATETABLE ( DATEADD ( DocumentDate[Date], -3, MONTH ),_DaysSelected ), "Range", "Qtrs" ),

 

Hi @BenCollins ,

 

These are the best kind of issues were the users solve it's own problem. 😂 (just kidding).

 

Don't forget to accept your answer as solution so it can help others.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.