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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Dax formula to find the average of each values between 2 dates

so Ive been trying to create a dax formular for som time that dose 2 things:

 

1)given a table with jobs that have open date and close dates, will return on each date of my already created date tabel the amount of jobs whos create date is earlier and closed date is later than the specified date.

ie. if my date table contained only one date being 3/1/2022 id get a 1 from my mesure 

open       |    closed 
1/1/2022->5/1/2022 

but if the date table was a weekly value and the next date to check was 10/1/2022 then it would return 1 then 0

if there were two jobs open over that period it would get a two 

job#1 -1/1/2022->5/1/2022 

job#2 -1/1/2022->6/1/2022 

 

this is needed to make a graph showing that the total number of jobs on a given day is slowly going down

 

the next step would be to get those same jobs and average the age between then from the start date.

meaning if it was open on the date being checked then find the time from creation to the date being cheked and average that age of jobs between every job open on that date being checked.

 

returning the mesure for a graph that will show the total average age of jobs along a timeline

open dateclosed date
1/1/20221/12/2022
1/1/20221/11/2022
1/1/20221/10/2022
1/1/20221/9/2022
1/1/20221/8/2022
1/1/20221/7/2022
1/1/20221/6/2022
1/1/20221/5/2022
1/1/20221/4/2022

 

date table and expected results :

Datemesure jobs open average age 
1/4/202294
1/5/202285
1/6/202276
1/7/202267
1/8/202258
1/9/202249
1/10/2022310
1/11/2022211
1/12/2022112

 

i appreciate any help, if i didnt think the dax im currently trying to make work wasnt completly crap id inclued that as well

Thanks 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to try these code to create measures to achieve your goal.

mesure jobs open = 
CALCULATE (
    COUNT ( 'Table'[Job ID] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[open date] <= MAX ( 'Table'[closed date] )
            && 'Table'[closed date] >= MAX ( 'Table'[closed date] )
    )
)
average age = 
AVERAGEX (
    FILTER (
        ALL ( 'Table' ),
        'Table'[open date] <= MAX ( 'Table'[closed date] )
            && 'Table'[closed date] >= MAX ( 'Table'[closed date] )
    ),
    MAX ( 'Table'[closed date] ) - 'Table'[open date] + 1
)

Result is as below.

RicoZhou_0-1661504665437.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to try these code to create measures to achieve your goal.

mesure jobs open = 
CALCULATE (
    COUNT ( 'Table'[Job ID] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[open date] <= MAX ( 'Table'[closed date] )
            && 'Table'[closed date] >= MAX ( 'Table'[closed date] )
    )
)
average age = 
AVERAGEX (
    FILTER (
        ALL ( 'Table' ),
        'Table'[open date] <= MAX ( 'Table'[closed date] )
            && 'Table'[closed date] >= MAX ( 'Table'[closed date] )
    ),
    MAX ( 'Table'[closed date] ) - 'Table'[open date] + 1
)

Result is as below.

RicoZhou_0-1661504665437.png

 

Best Regards,
Rico Zhou

 

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

amitchandak
Super User
Super User

@Anonymous , Refer if on the two blogs or the attached files after signature can help

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970

 

https://community.powerbi.com/t5/Community-Blog/How-to-divide-distribute-values-between-start-date-or-end-date/ba-p/1503785

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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