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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
SteveM123
Regular Visitor

Measure to aggregate a count of objects meeting two criteria

Hi,

 

I have a Calendar table with a dates field and an Objects table, the Objects table includes a column with a 'born on date' and a status field for 'active' or 'inactive'. I would like a measure that cycles through every Calendar date within a time span selected by a slicer and aggregates a count of units that have a 'born on date' falling within that selected time span and that also has a Object status = "active"

 

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from FreemanZ.

 

Hi @SteveM123 ,

 

Based on your description, l created simple test data:

vlinhuizhmsft_0-1730709228883.png

Create a measure:

Measure = 
VAR _startdate=MIN('Calendar'[Date])
VAR _enddate=MAX('Calendar'[Date])
VAR _interval=DATEDIFF(_startdate,_enddate,DAY)
RETURN
IF(MAX('Objects'[Start Date])<=_enddate&&OR(MAX('Objects'[End Date])>_startdate,MAX('Objects'[End Date])=BLANK()),DIVIDE(CALCULATE(COUNTROWS('Objects')),_interval))

 

The result is as follows:

vlinhuizhmsft_1-1730709455269.png

 

Best Regards,
Zhu
Community Support Team

 

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

View solution in original post

4 REPLIES 4
SteveM123
Regular Visitor

Thanks Zhu, I just tried your proposed measure and it does work, except for the case when a user applies a slicer on the pivot table against other fields in the Objects table in order to limit the population of Objects to be considered, for example by its geographic location.

Is there a way to modify this measure so that the context of filters applied on the pivot chart against the Objects table are also considered?

 

Thanks again!

Anonymous
Not applicable

Thanks for the reply from FreemanZ.

 

Hi @SteveM123 ,

 

Based on your description, l created simple test data:

vlinhuizhmsft_0-1730709228883.png

Create a measure:

Measure = 
VAR _startdate=MIN('Calendar'[Date])
VAR _enddate=MAX('Calendar'[Date])
VAR _interval=DATEDIFF(_startdate,_enddate,DAY)
RETURN
IF(MAX('Objects'[Start Date])<=_enddate&&OR(MAX('Objects'[End Date])>_startdate,MAX('Objects'[End Date])=BLANK()),DIVIDE(CALCULATE(COUNTROWS('Objects')),_interval))

 

The result is as follows:

vlinhuizhmsft_1-1730709455269.png

 

Best Regards,
Zhu
Community Support Team

 

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

SteveM123
Regular Visitor

Hi,

Thanks for that reply, but in my attempt to be succinct, I made a mistake in describing the scenario. A unit can be currently active, or it can be currently  inactive, but even a unit that is inactive today, was active at some earlier point in time. As such, my Objects table has both a 'born on date', call it a 'start date' and a 'decommissioned date' , lets call it an 'end date'

So I should have stated that the goal is to aggregate the number of Objects in the Objects table that were active for the slicer selected period, including objects that may be inactive today, but were active back during the period selected by the slicer.

So perhaps I need a measure that cycles through all calendar dates within the slicer selected period and for each of those dates, loops through the Objects table and aggregates a count of objects in the object table that have a 'start date' before the calendar date and either no 'end date' or an 'end date that is later than the current calendar date being evaluated. I would then divide that aggregated number by the number of days in the slicer selected peroid to obtain an effective count of operating units for the period which may or may not be a whole number

FreemanZ
Super User
Super User

hi @SteveM123 ,

 

try to:

1. relate the calendar table and objects table.

2. plot the slicer with calendar[date]

3.plot a measure like:

measure =

COUNTROWS(

  FILTER(objects, objects[status]="active")

)

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.