Forum Discussion

NH's avatar
NH
Icon for Advocate II rankAdvocate II
7 years ago
Solved

Help Need to find Day delta in either Power Query or DAX formuale

Hi   I've a shipment data which need to find the day different for a given same shipment ID where  its Shipment date changes. In Excel I'm using this formaule the get the result but like to find o...
  • ofirk's avatar
    ofirk
    7 years ago

    Hi NH,

    I didn't realize there could be more than 2 changes.

    In this case, this should work (assuming that your data is arranged in order by shipment IDs, like in your example)

     

     

    Day_delta = 
    IF([Index] <> MAXX(FILTER(Table1, [Shipment ID] = EARLIER([Shipment ID])), [Index]), 
    DATEDIFF(
        MAXX(
            FILTER(Table1,  
                    [Index] = EARLIER([Index])), 
            [Shipment Date Change]), 
        MAXX(
            FILTER(Table1,  
                    [Index] = EARLIER([Index]) + 1), 
            [Shipment Date Change]), 
        DAY))

     

    The results look like this:

    Explanation:

    For all rows where the Index is not the maximum index for the shipment ID (meaning, not the last index of a shimpent id), I use the DATEDIFF by DAY, with the following variables:

    - the date with the current index

    - the date with the next index