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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
crisher
Helper I
Helper I

Count Rows for Previous Quarter

Hello, I have tried multiple ways to calculate the number of records in this table from the previous quarter:

 

Registrations Prev Qtr = CALCULATE(COUNTROWS(Registration), PREVIOUSQUARTER(Registration[Registration_Date__c]))

Registrations Prev Qtr = CALCULATE(COUNTROWS(Registration), PREVIOUSQUARTER(DimDate[Date]))

Registrations Prev Qtr = CALCULATE(COUNT(Registration[Id]), PREVIOUSQUARTER(DimDate[Date]))
--These two come back as (Blank) results. And, the DimDate table is marked as the Date Table in the model.

Registrations Prev Qtr = CALCULATE(COUNTROWS(Registration), DATEADD(DimDate[Date], -1, QUARTER))

Registrations Prev Qtr = CALCULATE(COUNT(Registration[Id]), DATEADD(DimDate[Date], -1, QUARTER))
--These one comes back with a much higher number than expected.

I have made this video to show what I am seeing: https://easierway-my.sharepoint.com/:v:/g/personal/crisher_1path_com/ETqUQgMzMO5EggdP5rT03KIBKQi_NYM...

I have reviewed this post as well. But, that solution didn't seem to help.

1 ACCEPTED SOLUTION
PaulOlding
Solution Sage
Solution Sage

I think it's because the PREVIOUSQUARTER function doesn't mean previous to today's date, it's the previous quarter to the earliest date in the current filter context.

You have the measure in a card, with no filter on date applied.  So, PREVIOUSQUARTER is going to be returning the dates in the quarter before the earliest date in your DimDate table.  Hopefully that's a period where there's no data in your fact table (otherwise you've got an issue with your date table) and is why the measure returns blank.

 

What happens if you apply a filter to the card visual only, setting DimDate[Date] to today's date?

View solution in original post

3 REPLIES 3
PaulOlding
Solution Sage
Solution Sage

I think it's because the PREVIOUSQUARTER function doesn't mean previous to today's date, it's the previous quarter to the earliest date in the current filter context.

You have the measure in a card, with no filter on date applied.  So, PREVIOUSQUARTER is going to be returning the dates in the quarter before the earliest date in your DimDate table.  Hopefully that's a period where there's no data in your fact table (otherwise you've got an issue with your date table) and is why the measure returns blank.

 

What happens if you apply a filter to the card visual only, setting DimDate[Date] to today's date?

So, that worked. The only issue then is applying that filter context within the DAX measure as I am using that measure in another measure to calculate a ratio. I suppose I need to open a different thread about that.

If you want the measure to always return the previous quarter to today you could have something like

 

PREVIOUSQUARTER(

CALCULATETABLE(ALL(DimDate), DimDate[Date] = TODAY()))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors