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

View all the Fabric Data Days sessions on demand. View schedule

Reply
instdes
Frequent Visitor

Count Cell Condition for X Amount of Days

I have a table where I want to count the cell occurance over a period of time.  I was able to accomplish an overall count by the measure: 

 

Count = CALCULATE(COUNT('OpenRecords'[Name]))

 

but when I try to calculate for the past 30 days, I get an error.  I was trying this and it was not working.

 

Count = CALCULATE(COUNT('OpenRecords'[Name]) >= TODAY()-30)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Easiest solution is to use Variables.  You also need to define which field has the date stored in it.  I've made some guesses

 

This would look like

 

Count = var filterDate = TODAY()-30
var output = CALCULATE(
	COUNT('OpenRecords'[Name]),
	'OpenRecords'[Date] >= filterDate
)
RETURN
output

 

The advantage of writing dax like the above is that you can test each step of your code if you ever need to bug fix.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Easiest solution is to use Variables.  You also need to define which field has the date stored in it.  I've made some guesses

 

This would look like

 

Count = var filterDate = TODAY()-30
var output = CALCULATE(
	COUNT('OpenRecords'[Name]),
	'OpenRecords'[Date] >= filterDate
)
RETURN
output

 

The advantage of writing dax like the above is that you can test each step of your code if you ever need to bug fix.

Anonymous
Not applicable

I should also add that this formula may not work in all contexts, because you might have additional filters which are constraining your data to less than the last 30 days.  If thats the case you'd need to add in some ALL or related statements to expand the context.  This requires thought as you need to understand how this will interact with your reports slicers and contexts.  An example might be:

 

Count = var filterDate = TODAY()-30
var output = CALCULATE(
	COUNT('OpenRecords'[Name]),
	ALL('OpenRecords'),
	'OpenRecords'[Date] >= filterDate
)
RETURN
output

(this would ignore any filters you've set that constrain the open records table).

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors