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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
agd50
Helper V
Helper V

DAX - DistinctCount Previous Quarter Error/Help

agd50_1-1690348798710.png 

Count of Incident (Previous Quarter) = 
VAR _Period = -1
VAR _Results =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Column] ),
    DATESINPERIOD ( 'Dim_Calendar'[Date],
    TODAY(),
    _Period,
    QUARTER
    ) )
RETURN
IF ( ISBLANK ( _Results ),
0,_Results )

This dax formula almost works for the finding the value of the previous quarter - It just only counts how many values exists in a column (ie counting a 2 value as 1 value). Example below:

agd50_2-1690349160999.png

Not what I want above - I want to get the real number which is the 18. 

Thanks

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@agd50 , You can get last qtr based on today, assuming no selection

 

This Qtr Today =
var _today = today()
var _max = eomonth(_today, if( mod(Month(_today),3) =0,0,3-mod(Month(_today),3)))
var _min = eomonth(_max,-3)+1
return
CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

Last Qtr Today =
var _today = today()
var _max = eomonth(_today, -1*if( mod(Month(_today),3) =0,3,mod(Month(_today),3)))
var _min = eomonth(_max,-3)+1
return
CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@agd50 , You can get last qtr based on today, assuming no selection

 

This Qtr Today =
var _today = today()
var _max = eomonth(_today, if( mod(Month(_today),3) =0,0,3-mod(Month(_today),3)))
var _min = eomonth(_max,-3)+1
return
CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

Last Qtr Today =
var _today = today()
var _max = eomonth(_today, -1*if( mod(Month(_today),3) =0,3,mod(Month(_today),3)))
var _min = eomonth(_max,-3)+1
return
CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Very impressive, don't know how you do it. 

Works perfectly

v-yanjiang-msft
Community Support
Community Support

Hi @agd50 ,

I think the problem is that the function DATESINPERIOD didn't return the correct period. Please use the below dax to create a new table to check if it can return the expected period:

vyanjiangmsft_0-1690535040413.png

DATESINPERIOD ( 'Dim_Calendar'[Date], TODAY (), -1, QUARTER )

As the returned table of  DATESINPERIOD function can only contain dates stored in the dates column. In other words, if the 'Dim_Calendar'[Date] column don't contain all the dates of previous quarter, the returned period wil be cutted off.

 

Best regards,

Community Support Team_yanjiang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

You are correct - it is counting from May - July instead of April - June 

agd50_0-1690774552640.png

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.