Forum Discussion
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
- p45calSolution 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)
- p45calSolution Supplier
Could you save me some time by attaching a workbook with these (source) data in please?
- SundarRajSuper User
Hi Casi , have a look at this file and let me know if this is what you re looking for? I'll attach the file and images of the output. You can see the code from Advance Editor in the PQ interface. Thanks
https://docs.google.com/spreadsheets/d/1EKubQ_sRc0n-ka1dx6k2xS3uDz0a_c3t/edit?usp=sharing&ouid=104752674875039603034&rtpof=true&sd=true- CasiHelper I
Hi Sundar,
This is what i am wanting but how did you do it?
Thank you
- SundarRajSuper 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. ThanksCreate 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.
- CasiHelper I
Hi,
This is the output i would like:
ceox_auditlogid ceox_incidentid ceox_newvalue ceox_oldvalue Incident.title Date Notified 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 10/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 11/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 12/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 13/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 14/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 15/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 16/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 17/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 18/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 19/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 20/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 21/03/2023 00:00 042b04cf-80bf-ed11-83fd-002248c70152 cb53f708-25ad-ed11-83ff-0022481b5e4e Open Ready Pending Information 1482728 22/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 22/02/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 23/02/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 24/02/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 25/02/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 26/02/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 27/02/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 28/02/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 01/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 02/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 03/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 04/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 05/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 06/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 07/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 08/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 09/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 10/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 11/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 12/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 13/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 14/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 15/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 16/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 17/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 18/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 19/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 20/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 21/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 22/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 23/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 24/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 25/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 26/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 27/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 28/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 29/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 30/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 31/03/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 01/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 02/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 03/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 04/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 05/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 06/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 07/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 08/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 09/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 10/04/2023 00:00 0610c234-a0b2-ed11-83ff-6045bd0b12c1 cb53f708-25ad-ed11-83ff-0022481b5e4e Pending Information Awaiting Validation 1482728 11/04/2023 00:00 1b72fab5-4522-ee11-9966-002248c87a56 cb53f708-25ad-ed11-83ff-0022481b5e4e Dismissed Notified 1482728 12/04/2023 00:00 02f496eb-4cbe-ed11-83fe-0022481b9548 666e9176-f5d7-4cf2-9067-d446b5aff3b8 Listed Notified 14597698 09/03/2023 00:00 02f496eb-4cbe-ed11-83fe-0022481b9548 666e9176-f5d7-4cf2-9067-d446b5aff3b8 Listed Notified 14597698 10/03/2023 00:00 02f496eb-4cbe-ed11-83fe-0022481b9548 666e9176-f5d7-4cf2-9067-d446b5aff3b8 Listed Notified 14597698 11/03/2023 00:00 02f496eb-4cbe-ed11-83fe-0022481b9548 666e9176-f5d7-4cf2-9067-d446b5aff3b8 Listed Notified 14597698 12/03/2023 00:00 02f496eb-4cbe-ed11-83fe-0022481b9548 666e9176-f5d7-4cf2-9067-d446b5aff3b8 Listed Notified 14597698 13/03/2023 00:00 02f496eb-4cbe-ed11-83fe-0022481b9548 666e9176-f5d7-4cf2-9067-d446b5aff3b8 Listed Notified 14597698 14/03/2023 00:00 1c965d4f-4ebe-ed11-83fe-0022481b9dcf 666e9176-f5d7-4cf2-9067-d446b5aff3b8 Notified Listed 14597698 15/03/2023 00:00 - V-yubandi-msftCommunity 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 - p45calSolution 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?)
- CasiHelper 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
- p45calSolution 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-msftCommunity Support