Forum Discussion

Casi's avatar
Casi
Helper I
1 year ago
Solved

Work out dates between one column on multi rows

Hi,

I have a table 'audit' containing all the different stages of an appeal. I need to work out the dates between the date the status was changed but I am struggling without a start date.

 

Can anyone please help.

  • In the attached, the same query adapted to a changed column name from Date Notified to createdon.

    It produces just short of 900k rows so I've reduced it to one row (to be able to attach it here) which means you'll need to refresh the query to see those rows. it takes a few seconds to generate those rows…

23 Replies

  • p45cal's avatar
    p45cal
    Solution Supplier

    Can you show how you expect the output to be?

    Ideally, attach a simple workbook with just these data (perhaps with a few more incidentids)

  • p45cal's avatar
    p45cal
    Solution Supplier

    Could you save me some time by attaching a workbook with these (source) data in please?

      • p45cal's avatar
        p45cal
        Solution Supplier

        Nearly there… this needs a login; can you make it available to all or share elsewhere please?

    • Casi's avatar
      Casi
      Helper I

      Hi Sundar,

      This is what i am wanting but how did you do it?

      Thank you

      • SundarRaj's avatar
        SundarRaj
        Super User

        Casi
        Below are the steps that I've done in the adv editor. Do let me know if there are any clarifications or explanations needed. Thanks

        • Create an Index Column Starting from 1: The first step is to add an index column that starts from 1 instead of 0. This is necessary because you want to refer to the second row in the [DateNotified] column, which will act as the end date. So, the index will start from 1 to point to the second row

        • Create a List of Dates: Use the [DateNotified] and [DateChanged] columns to generate a list of dates for each row. This step creates a range of dates between the two columns.

          Expand into Separate Rows: Finally, expand the list of dates into separate rows to get the desired output.

          Error Handling (Try-Otherwise): Since the last row will have an index of '4' but only 3 i.e. (Row 0 to Row 3) rows exist, the process may not return any data for the last row. To prevent errors, the Try-Otherwise condition is used, ensuring that if no data is returned, the last value is used instead.

         

  • Hi,

    This is the output i would like:

    ceox_auditlogidceox_incidentidceox_newvalueceox_oldvalueIncident.titleDate Notified
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272810/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272811/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272812/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272813/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272814/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272815/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272816/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272817/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272818/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272819/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272820/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272821/03/2023 00:00
    042b04cf-80bf-ed11-83fd-002248c70152cb53f708-25ad-ed11-83ff-0022481b5e4eOpen ReadyPending Information148272822/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272822/02/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272823/02/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272824/02/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272825/02/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272826/02/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272827/02/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272828/02/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272801/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272802/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272803/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272804/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272805/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272806/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272807/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272808/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272809/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272810/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272811/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272812/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272813/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272814/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272815/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272816/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272817/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272818/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272819/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272820/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272821/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272822/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272823/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272824/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272825/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272826/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272827/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272828/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272829/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272830/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272831/03/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272801/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272802/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272803/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272804/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272805/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272806/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272807/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272808/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272809/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272810/04/2023 00:00
    0610c234-a0b2-ed11-83ff-6045bd0b12c1cb53f708-25ad-ed11-83ff-0022481b5e4ePending InformationAwaiting Validation148272811/04/2023 00:00
    1b72fab5-4522-ee11-9966-002248c87a56cb53f708-25ad-ed11-83ff-0022481b5e4eDismissedNotified148272812/04/2023 00:00
    02f496eb-4cbe-ed11-83fe-0022481b9548666e9176-f5d7-4cf2-9067-d446b5aff3b8ListedNotified1459769809/03/2023 00:00
    02f496eb-4cbe-ed11-83fe-0022481b9548666e9176-f5d7-4cf2-9067-d446b5aff3b8ListedNotified1459769810/03/2023 00:00
    02f496eb-4cbe-ed11-83fe-0022481b9548666e9176-f5d7-4cf2-9067-d446b5aff3b8ListedNotified1459769811/03/2023 00:00
    02f496eb-4cbe-ed11-83fe-0022481b9548666e9176-f5d7-4cf2-9067-d446b5aff3b8ListedNotified1459769812/03/2023 00:00
    02f496eb-4cbe-ed11-83fe-0022481b9548666e9176-f5d7-4cf2-9067-d446b5aff3b8ListedNotified1459769813/03/2023 00:00
    02f496eb-4cbe-ed11-83fe-0022481b9548666e9176-f5d7-4cf2-9067-d446b5aff3b8ListedNotified1459769814/03/2023 00:00
    1c965d4f-4ebe-ed11-83fe-0022481b9dcf666e9176-f5d7-4cf2-9067-d446b5aff3b8NotifiedListed1459769815/03/2023 00:00
  • V-yubandi-msft's avatar
    V-yubandi-msft
    Community Support

    Hi Casi ,

    Thanks for posting your query in the Microsoft Fabric Community.  The solution provided by SundarRaj , effectively addresses your scenario. By utilizing Power Query indexing and sorting capabilities, it enables the calculation of durations between each status change, even in the absence of a dedicated  start date column.

     

    So please review the solution shared by SundarRaj and let us know if you need any additional clarification or details.

     

    Many thanks to p45cal and SundarRaj  for your valuable contributions.

     

    Best regards,
    Yugandhar | Community Support Team

    • Casi's avatar
      Casi
      Helper I

      Sorry i still need assistance

      • p45cal's avatar
        p45cal
        Solution Supplier

        Seems every obstacle under the sun is being presented to us:

         

         

         

        Meanwile I'm looking at SundarRaj 's Excel file's Power Query query.

        Meanwhile, one question. are you grouping by ceox_auditlogid or ceox_incidentid or something else?

  • p45cal's avatar
    p45cal
    Solution Supplier

    In the attached workbook (stolen from SundarRaj !) I've put a variation of his query; it's based on grouping by ceox_incidentid (the only one I can reasonably group on) but I notice in the .pbix file that you might instead want to group on ceox_auditlogid, for which I'll have to tweak.

    Your limited source table is on Sheet2 and the query result is on Sheet1.

    However there's another question: in the attached, the column DatesLists has inclusive dates, meaning that the cross-over dates appear with both old value and new value:

     

     

    Is this how you want it?

     

    You should add to the data table on Sheet2 then refresh the query on Sheet1 (right-click somewhere in that table and choose Refresh) to check that it's giving you the results you want.

    (There's another thing I haven't so far coded for and that's for the possibility of any incident going 'backwards', that is for example, could it go from Awaiting Validation to Pending Information, and later go back to Awaiting Validation?)

     

     

    • Casi's avatar
      Casi
      Helper I

      Hi, Thank you for getting back to me. 

      For the first questions i would like the record for 'ceox_newvalue pending information' not to be there for the 10/03.

      Second question no it shouldnt. 

      Ive added the query to myreport but I am getting the error on some records when expanding:

      Thanks for all your help

      • p45cal's avatar
        p45cal
        Solution Supplier

        re:"For the first questions i would like the record for 'ceox_newvalue pending information' not to be there for the 10/03."

        I've updated the file I attached to previous message, perhaps you can confirm it gives the right dates now.

         

        re: "but I am getting the error on some records when expanding"

        I'd really need to see the source data that causes that; I've had a go at guessing what might cause it but without success…

        You could replace the existing source data in my file with your error-causing data then save and attach it here.

         

  • V-yubandi-msft's avatar
    V-yubandi-msft
    Community Support

    Hi Casi ,

    As mentioned  p45cal  earlier, could you please attach the data.  It would be really helpful in accurately resolving the issue. 

     

    Thanks.