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

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

Reply
cmac1
Regular Visitor

Calculate a Measure Based on Date Filter

I am trying to calculate a measure based on my date filter in the report.  Here is the formula I am using to count the days between between the start and end date of the filter:

 

Count Days =
var start_Date=FIRSTDATE(ALLSELECTED('calendar_auto'[Date]))
var end_Date=LASTDATE(ALLSELECTED('calendar_auto'[Date]))
var current_Start=MIN('public inventory_binadjustment'[transaction_date_local])
var current_end=MAX('public inventory_binadjustment'[transaction_date_local])
return
DATEDIFF(MAX(start_Date,current_Start),MIN(end_Date,current_end),DAY)
 
It returns the correct amount of days.  My next step is to have another measure that calculates the average daily usage of each item in the table based on that amount of days.  In the example the days from the filter represents 182 days.  However, you can see in the table the "Count Days" is looking at the first and last dates for that specific item instead of the complete 182 days. 
 
Any suggestion on how I can get the measure to "Average Daily Usage" to calculate based on the first and last dates of the filter instead of just the days for that specific item?
 

Capture.PNG

 
1 REPLY 1
lbendlin
Super User
Super User

whenever you see a behavior like that you need to think about the filter context. By default it only looks at the current "row". You need to use ALL() or ALLSELECTED() on your fact table (not the dates table) to expand the context according to your requirements.

 

Please provide sample data in usable format and show the expected outcome.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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