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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
OliTFD
Regular Visitor

How to calculate the average count of rows? Persons with dif. start and end dates in dif. groups

I have a table with different persons, all with different start and end dates (of employment).
I want to calculate the count of them for eyery time. But not only for every day, I also need to find the average for time periods month and quarter.
The persons belong to different groups. Here is where I get lost:
If I calculate countrows in a calculated column of the datetable, filtering on the groups is not applied to this calculation.
So any following calculation like average is not influenced by the group. Even filtering with something like
Persons[Group]=SELECTEDVALUE(Persons[Group]) does not work, because measures can not be used inside calculated colums, as I learned.
Any idea how to solve this?

The table is simple like

NameGroupStartdateEnddate
A101.01.2123.03.21
B201.02.2109.10.21
C301.04.2120.12.21
D402.05.2106.09.21
E113.02.2112.04.21
F202.06.2123.07.21
G303.04.2128.10.21
H405.07.2104.09.21
I112.06.2113.11.21
J201.01.2123.08.21
K301.02.2109.10.21
L401.04.2120.12.21
M102.05.2106.09.21


Datetable is simple Calendarauto. No relationship between the two tables.
The (not correctly working) calculated colum was

Count of active Persons per Day =
CALCULATE(COUNTROWS(Persons),
FILTER(Persons,Persons[Startdate]<=(Days[Date])),
FILTER(Persons,Persons[Enddate]>=(Days[Date])),
FILTER(Persons,Persons[Group]=SELECTEDVALUE(Persons[Group]))
)
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@OliTFD , Try like

 

averageX(values(Days[Date]), calculate(COUNTROWS(Persons),
FILTER(Persons,Persons[Startdate]<=(Days[Date]) && Persons[Enddate]>=(Days[Date]) && Persons[Group]=SELECTEDVALUE(Persons[Group]))
))

 

or

 

averageX(values(Days[Date]), calculate(COUNTROWS(Persons),
FILTER(Persons,Persons[Startdate]<=(Days[Date]) && Persons[Enddate]>=(Days[Date]) )
))

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@OliTFD , Try like

 

averageX(values(Days[Date]), calculate(COUNTROWS(Persons),
FILTER(Persons,Persons[Startdate]<=(Days[Date]) && Persons[Enddate]>=(Days[Date]) && Persons[Group]=SELECTEDVALUE(Persons[Group]))
))

 

or

 

averageX(values(Days[Date]), calculate(COUNTROWS(Persons),
FILTER(Persons,Persons[Startdate]<=(Days[Date]) && Persons[Enddate]>=(Days[Date]) )
))

Great! Works like magic! Thank you!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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