Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
TerriAki
Frequent Visitor

Add a new row per ID with (last date +1 day)

Hi, 

 

Any help would be appreciated on the following problem please:

 

Trying to add a new row per ID with the date value as the last date plus 1 day.  Expected result is in red font, the actual data has over 4 million rows:

 

T&A Table:

Employee IDDate             Status  Week Ending
128/03/2020RD28/03/2020 00:00
129/03/2020S04/04/2020 00:00
130/03/2020S04/04/2020 00:00
131/03/2020S04/04/2020 00:00
101/04/2020RD04/04/2020 00:00
102/04/2020  
228/03/2020S04/04/2020 00:00
229/03/2020RD04/04/2020 00:00
230/03/2020TW11/04/2020 00:00
231/03/2020TW11/04/2020 00:00
201/04/2020111/04/2020 00:00
202/04/2020RD11/04/2020 00:00
203/04/2020111/04/2020 00:00
204/04/2020  
328/03/2020RD11/04/2020 00:00
329/03/2020AL18/04/2020 00:00
330/03/2020HA18/04/2020 00:00
331/03/2020TW18/04/2020 00:00
301/04/2020RD18/04/2020 00:00
302/04/2020TW18/04/2020 00:00
303/04/2020RD18/04/2020 00:00
304/04/2020125/04/2020 00:00
305/04/2020TW25/04/2020 00:00
306/04/2020125/04/2020 00:00
307/04/2020RD25/04/2020 00:00
308/04/2020TW25/04/2020 00:00
309/04/2020  

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @TerriAki ,

 

Paste this into a new blank query using Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdJNC4JAEAbgvyJ7FpzZ1bJugkJBpww8iAehJaSyIDv075sOkrs6uuDn7sO7O6NlKbL78/b4aO3tU+GLtO403fKu7t4veii0vnpZe27ai6j8UiCNyTgAFUiQQC/H1BjxALYAf7oZ0JxOCAM6JqQCZ4muErCf6Dc6SaVdExsq7ZLmQ42aTgVdEDmKztSoCmeltOvnqXIJVZNfn6fDViWHH40ZarRql8zScas4Ov4BeDrs1UKqck8NrbbKiJORvT5PV86ha3unPI2X16++", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    promoteHeads = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    chgTypes = Table.TransformColumnTypes(promoteHeads,{{"Week Ending", type datetime}, {"Date", type date}}),
    groupRows = Table.Group(chgTypes, {"Employee ID"}, {{"data", each _, type table [Employee ID=nullable text, Date=nullable date, Status=nullable text, Week Ending=nullable datetime]}}),
    addNestedRow =
        Table.TransformColumns(
            groupRows,
            {"data", each
            Table.InsertRows(_, 0, 
                {
                    [Employee ID = List.Max(_[Employee ID]), Date = Date.AddDays(List.Max(_[Date]), 1), Status = null, Week Ending = null]
                }
            )}
        ),
    expandDataColumn = Table.ExpandTableColumn(addNestedRow, "data", {"Date", "Status", "Week Ending"}, {"Date", "Status", "Week Ending"})
in
    expandDataColumn

 

This gives me the following output:

BA_Pete_0-1647874429480.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
TerriAki
Frequent Visitor

This is perfect, thank you for the quick response. 

BA_Pete
Super User
Super User

Hi @TerriAki ,

 

Paste this into a new blank query using Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdJNC4JAEAbgvyJ7FpzZ1bJugkJBpww8iAehJaSyIDv075sOkrs6uuDn7sO7O6NlKbL78/b4aO3tU+GLtO403fKu7t4veii0vnpZe27ai6j8UiCNyTgAFUiQQC/H1BjxALYAf7oZ0JxOCAM6JqQCZ4muErCf6Dc6SaVdExsq7ZLmQ42aTgVdEDmKztSoCmeltOvnqXIJVZNfn6fDViWHH40ZarRql8zScas4Ov4BeDrs1UKqck8NrbbKiJORvT5PV86ha3unPI2X16++", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    promoteHeads = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    chgTypes = Table.TransformColumnTypes(promoteHeads,{{"Week Ending", type datetime}, {"Date", type date}}),
    groupRows = Table.Group(chgTypes, {"Employee ID"}, {{"data", each _, type table [Employee ID=nullable text, Date=nullable date, Status=nullable text, Week Ending=nullable datetime]}}),
    addNestedRow =
        Table.TransformColumns(
            groupRows,
            {"data", each
            Table.InsertRows(_, 0, 
                {
                    [Employee ID = List.Max(_[Employee ID]), Date = Date.AddDays(List.Max(_[Date]), 1), Status = null, Week Ending = null]
                }
            )}
        ),
    expandDataColumn = Table.ExpandTableColumn(addNestedRow, "data", {"Date", "Status", "Week Ending"}, {"Date", "Status", "Week Ending"})
in
    expandDataColumn

 

This gives me the following output:

BA_Pete_0-1647874429480.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.