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
Anonymous
Not applicable

Counting rows between two dates

I want to create a measure that checks to see if there is an entry between a certain set of dates.  The dates are the absolute max date of all entries created, and one year prior to that.  The maximum entry date in my data is 12/9/2021, so it should be looking between 12/9/2020-12/9/2021, however it's not working properly.  It is telling me that certain accounts have entries made when they are outside of those dates.

 

Here is my formula:

a_Test Home Office =
var maxdate = CALCULATE(MAX('Usage Statistics'[CreateDate]),ALL('Usage Statistics'))
var startdate = CALCULATE(maxdate-365,ALL('Usage Statistics'))
return
CALCULATE(COUNTAX('Usage Statistics','Usage Statistics'[ObjectType]),'Usage Statistics'[ObjectType]="NB Exhibit Exhibit",'Usage Statistics'[CreateDate]<=maxdate,'Usage Statistics'[CreateDate]>=startdate,'Usage Statistics'[Group]="Home Office")+CALCULATE(COUNTAX('Usage Statistics','Usage Statistics'[ObjectType]),'Usage Statistics'[ObjectType]="Main Exhibit Account",'Usage Statistics'[CreateDate]<=maxdate,'Usage Statistics'[CreateDate]>=startdate,'Usage Statistics'[Group]="Home Office")
2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

You could try this measure

a_Test Home Office =
VAR maxdate = CALCULATE ( MAX ( 'Usage Statistics'[CreateDate] ), ALL ( 'Usage Statistics' ) )
VAR startdate = EDATE ( maxdate, -12 )
RETURN
    CALCULATE (
        COUNT ( 'Usage Statistics'[ObjectType] ),
        'Usage Statistics'[ObjectType] IN { "NB Exhibit Exhibit", "Main Exhibit Account" },
        'Usage Statistics'[CreateDate] <= maxdate,
        'Usage Statistics'[CreateDate] >= startdate,
        'Usage Statistics'[Group] = "Home Office"
    )

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

lbendlin
Super User
Super User

var startdate = CALCULATE(max('Usage Statistics'[CreateDate]),ALL('Usage Statistics'),'Usage Statistics'[CreateDate])>=EDATE(maxdate,-12))

 

And then you can use a DATESBETWEEN filter.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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