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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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))

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?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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