Forum Discussion

HILGARTH's avatar
HILGARTH
Frequent Visitor
2 years ago
Solved

Counting days between different changes made to a record

To a table a copy of the initial record is added when there was a change.

I would like to calculate the days between these changes so that I know how many days passed between the different kinds of status.

 

Record ID

Product

Status

Record created

Date of last change

 

1

Trouser

Ordered

2023-10-11

2023-10-11

 

1

Trouser

Shipped

2023-10-11

2023-10-12

 

1

Trouser

Delivered

2023-10-11

2023-10-23

 

 

This means I should be able to display results like:

Days between Status “Ordered” and “Shipped” = 1 day

Days between Status “Shipped” and “Delivered” = 12 days

Days between Status "Shipped” and “Delivered" = 11 days

How to do this in Power BI?

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi HILGARTH,

    May I ask if this is the expected output you are looking for? Based on your description, I calculated days between Status Ordered and Shipped and Shipped and Delivered, The following table shows the effect of the display.

     

     

     

    Step: Create a new Calculated column, and drag the new Calculated column to the table visual.

    Column =
    
    DATEDIFF (
    
        CALCULATE (
    
            MAX ( 'Table'[Date of last change] ),
    
            FILTER (
    
                ALL ( 'Table' ),
    
                EARLIER ( 'Table'[Date of last change] ) > 'Table'[Date of last change]
    
                    && 'Table'[Record ID] = EARLIER ( 'Table'[Record ID] )
    
            )
    
        ),
    
        'Table'[Date of last change],
    
        DAY
    
    )

     

    If this does not work, could you please share some sample data without sensitive information and expected output.
    How to provide sample data in the Power BI Forum - Microsoft Fabric Community

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi HILGARTH,

    May I ask if this is the expected output you are looking for? Based on your description, I calculated days between Status Ordered and Shipped and Shipped and Delivered, The following table shows the effect of the display.

     

     

     

    Step: Create a new Calculated column, and drag the new Calculated column to the table visual.

    Column =
    
    DATEDIFF (
    
        CALCULATE (
    
            MAX ( 'Table'[Date of last change] ),
    
            FILTER (
    
                ALL ( 'Table' ),
    
                EARLIER ( 'Table'[Date of last change] ) > 'Table'[Date of last change]
    
                    && 'Table'[Record ID] = EARLIER ( 'Table'[Record ID] )
    
            )
    
        ),
    
        'Table'[Date of last change],
    
        DAY
    
    )

     

    If this does not work, could you please share some sample data without sensitive information and expected output.
    How to provide sample data in the Power BI Forum - Microsoft Fabric Community

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

    • HILGARTH's avatar
      HILGARTH
      Frequent Visitor

      Dear Yang

      Great - that works!

      thx & best regards

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    =VAR _d=MAX(Table[Date of last change]) RETURN _d+1-COALESCE(CACULATE(MAX(Table[Date of last change]),Table[Date of last change]<_d,ALLEXCEPT(Table,Table[Record ID]),MAX(Table[Record Created]))