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

How to find an average row count of one table for each date category in a related table using DAX?

Hi folks, 

I am attempting to create a measure that calculates average submissions per pay period where submissions are stored in one table and pay periods are stored in a related table. 

 

Here is the relationship between the two tables. It is a 1:Many on Date and Created Date.

PayPeriodAverage.png

 

 

Dates Table Sample:

DatePay Period
6/30/20196/23/2019 - 7/06/2019
7/1/20196/23/2019 - 7/06/2019
7/3/20196/23/2019 - 7/06/2019
7/14/20197/07/2019 - 7/20/2019
7/17/20197/07/2019 - 7/20/2019
7/19/20197/07/2019 - 7/20/2019
7/21/20197/21/2019 - 8/03/2019
7/24/20197/21/2019 - 8/03/2019

 

 

Service Desk Table Sample:

idCreated DateEmployee
16/23/2019Smith, Bob
26/23/2019Roberts, Laurie
36/24/2019Samuel, Tyler
47/01/2019Smith, Bob
57/05/2019Roberts, Laurie
67/07/2019Smith, Bob
77/09/2019Collins, Gabi
87/18/2019Collins, Gabi
97/19/2019Samuel, Tyler
107/20/2019Smith, Bob
117/25/2019Roberts, Laurie
127/28/2019Smith, Bob
138/01/2019Samuel, Tyler

 

For this sample data, the measure would return 4.333333. Pay period 6/23/2019-7/06/2019 had 5 requests, 7/07/2019 - 7/20/2019 had 5 requests, and 7/21/2019 - 8/03/2019 had 3 requests. 13 total requests/3 total pay periods = 4.33333.

Been stuck on this one for a while and would appreciate any help you all can offer. 

Thanks

-Jacob

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @Anonymous ,

this measure should work: 

Average over Pay Periods = AVERAGEX(VALUES(Dates[Pay Period]), COUNTROWS(RELATEDTABLE('Service Desk')))

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

3 REPLIES 3
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

If date column in your date table have all the value in create column, the @ImkeF 's formula should work fine, but if the relation is not complete, such as some value did not in Dates table, for example, the sample table you have shared, we can use the following formula to meet your requirement:

 

AverageMeasure = 
AVERAGEX (
    ADDCOLUMNS (
        DISTINCT ( 'DatesTable'[Pay Period] ),
        "Start", DATEVALUE ( LEFT ( [Pay Period], FIND ( " - ", [Pay Period] ) ) ),
        "End", DATEVALUE (
            RIGHT ( [Pay Period], LEN ( [Pay Period] ) - FIND ( " - ", [Pay Period] ) - 2 )
        )
    ),
    COUNTROWS (
        FILTER (
            'ServiceDeskTable',
            AND ( [Created Date] >= [Start], [Created Date] <= [End] )
        )
    )
)

2.PNG

 


BTW, pbix as attached.

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-lid-msft,

I apologize for the confusion my sample data caused. My date table does contain every date, but I excluded a lot of dates as I wanted to have a few pay periods in order to best exemplify what I was trying to achieve.  I accepted @ImkeF 's answer as it is simple and most likely applicable to others who are trying to perform similar operations. However, your answer is most correct given the sample data I provided.

Thank you for your help 🙂

ImkeF
Community Champion
Community Champion

Hi @Anonymous ,

this measure should work: 

Average over Pay Periods = AVERAGEX(VALUES(Dates[Pay Period]), COUNTROWS(RELATEDTABLE('Service Desk')))

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

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!

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