Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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:   In my tabular I have a seperate column ...
  • v-henryk-mstf's avatar
    5 years ago

    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

     

     

    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.