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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JB17
Frequent Visitor

Average Days

Hi everyone,

Can you help me create dax for below? I need to create a measure to calculate the average days of processing date for system ID 0000-0000-0000. So let say for the first two rows, I want to calculate how many days do we get from 02/06/2018 to 08/08/2018? and the average per month? Thanks in advance!

 

JB17_0-1689757231023.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @JB17 ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1689910713068.png

(2) We can create  measures. 

ProcessingDaysDifference = 
VAR CurrentDate = MAX('Table'[Processing Date])
VAR PreviousDate =
    CALCULATE(
        MAX('Table'[Processing Date]),
        FILTER(
            ALL('Table'),
            'Table'[system ID]=MAX('Table'[system ID]) &&
            'Table'[Processing Date] < CurrentDate
        )
    )
RETURN
DATEDIFF(PreviousDate, CurrentDate, DAY)
AverageDaysPerMonth = 
var _min=CALCULATE(MIN('Table'[Processing Date]),FILTER(ALL('Table'),'Table'[system ID]=MAX('Table'[system ID]) && YEAR('Table'[Processing Date])=YEAR(MAX('Table'[Processing Date])) && MONTH('Table'[Processing Date])=MONTH(MAX('Table'[Processing Date]))))
var _max=CALCULATE(MAX('Table'[Processing Date]),FILTER(ALL('Table'),'Table'[system ID]=MAX('Table'[system ID]) && YEAR('Table'[Processing Date])=YEAR(MAX('Table'[Processing Date])) && MONTH('Table'[Processing Date])=MONTH(MAX('Table'[Processing Date]))))
var _day=IF( DATEDIFF(_min, _max, DAY)=0,1,DATEDIFF(_min, _max, DAY))
var _count=COUNTROWS(FILTER(ALL('Table'),'Table'[system ID]=MAX('Table'[system ID]) && YEAR('Table'[Processing Date])=YEAR(MAX('Table'[Processing Date])) && MONTH('Table'[Processing Date])=MONTH(MAX('Table'[Processing Date]))))
return DIVIDE(_day,_count,0)

(3) Then the result is as follows.

vtangjiemsft_1-1689910754157.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

1 REPLY 1
Anonymous
Not applicable

Hi @JB17 ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1689910713068.png

(2) We can create  measures. 

ProcessingDaysDifference = 
VAR CurrentDate = MAX('Table'[Processing Date])
VAR PreviousDate =
    CALCULATE(
        MAX('Table'[Processing Date]),
        FILTER(
            ALL('Table'),
            'Table'[system ID]=MAX('Table'[system ID]) &&
            'Table'[Processing Date] < CurrentDate
        )
    )
RETURN
DATEDIFF(PreviousDate, CurrentDate, DAY)
AverageDaysPerMonth = 
var _min=CALCULATE(MIN('Table'[Processing Date]),FILTER(ALL('Table'),'Table'[system ID]=MAX('Table'[system ID]) && YEAR('Table'[Processing Date])=YEAR(MAX('Table'[Processing Date])) && MONTH('Table'[Processing Date])=MONTH(MAX('Table'[Processing Date]))))
var _max=CALCULATE(MAX('Table'[Processing Date]),FILTER(ALL('Table'),'Table'[system ID]=MAX('Table'[system ID]) && YEAR('Table'[Processing Date])=YEAR(MAX('Table'[Processing Date])) && MONTH('Table'[Processing Date])=MONTH(MAX('Table'[Processing Date]))))
var _day=IF( DATEDIFF(_min, _max, DAY)=0,1,DATEDIFF(_min, _max, DAY))
var _count=COUNTROWS(FILTER(ALL('Table'),'Table'[system ID]=MAX('Table'[system ID]) && YEAR('Table'[Processing Date])=YEAR(MAX('Table'[Processing Date])) && MONTH('Table'[Processing Date])=MONTH(MAX('Table'[Processing Date]))))
return DIVIDE(_day,_count,0)

(3) Then the result is as follows.

vtangjiemsft_1-1689910754157.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.