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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Average days between two dates

I try to write a measure which can calculate average days between orderdate and register_orderdate. In slicer two dates can be selected. For example:

 

7.PNG

In my tabular I have a seperate column for date which I use in slicer; dateKey_FK (20210401 , 20210610,...)

 

and in table in report:

 

77.PNG

Can you please guide me how I can write measure for 'Average_registerdate'

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your request, I did the following test: dateKey_FK is a separate date list, and there is no relationship between the two tables. Reference is as follows:

 

avg_day = 
VAR a =
    MIN ( dateKey_FK[Date] )
VAR b =
    MAX ( dateKey_FK[Date] )
VAR c =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Orderdate] >= a
                && 'Table'[RegisterOrderdate] <= b
        )
    )
VAR d =
    CALCULATE (
        SUM ( 'Table'[day_diff] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Orderdate] >= a
                && 'Table'[RegisterOrderdate] <= b
        )
    )
RETURN
    d / c

 

v-henryk-mstf_0-1618215739878.png

 

Below is the sample pbix file.


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.

Best Regards,
Henry

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

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

Nice day

in excel I track tickets to validate the aging, but at the time of replicating it in PowerBi, I can not tell you in what case the ticket is not closed tell me how many days it has been open

angiem_96_0-1644425266278.png

Generate a column that said End_Date and tells me the day we are on and I can calculate with datediff the values between the 2 dates, but I need to add what is indicated in the excel form.

I appreciate your help with the topic

Since then I must typify it like this:

=YES. ERROR(IF([@[Open Days]]="CLOSED";" Closed";IF(Y([@[Open Days]]>=0;[ @[Open Days]]<=15);" 0-15 Days";Y(Y([@[Open Days]]>15;[ @[Open Days]]<=30);" 16-30 Days";Y(Y([@[Open Days]]>30;[ @[Open Days]]<=45);" 31-45 Days";SI([@[Open Days]]>=45;" Greater than 45 Days";" Verify")))));" Review")

I have all this in excel. and I want to replicate it in PowerBi

v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your request, I did the following test: dateKey_FK is a separate date list, and there is no relationship between the two tables. Reference is as follows:

 

avg_day = 
VAR a =
    MIN ( dateKey_FK[Date] )
VAR b =
    MAX ( dateKey_FK[Date] )
VAR c =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Orderdate] >= a
                && 'Table'[RegisterOrderdate] <= b
        )
    )
VAR d =
    CALCULATE (
        SUM ( 'Table'[day_diff] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Orderdate] >= a
                && 'Table'[RegisterOrderdate] <= b
        )
    )
RETURN
    d / c

 

v-henryk-mstf_0-1618215739878.png

 

Below is the sample pbix file.


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.

Best Regards,
Henry

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 , This filter is on which date- orderdate or register_orderdate ?

 

you can get Avg as

averageX(Table, Datediff(orderdate, register_orderdate, day))

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

It's based on datekey_FK. 

@Anonymous , sorry I did not get it yet. But how datekey_FK is related to the data you have shown or how you want it to be related?

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.