cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Matty Regular Visitor
Regular Visitor

Insert row with reference to an existing row - Power Query...

Hi Team,

 

Looking for some help inserting a new row (record) to my 2 column table based on the minimum date in one of the columns.

 

Here's my table: 

 

Week_IndexStart_Date
109/04/2018
216/04/2018
323/04/2018
430/04/2018

 

And I want it to look as follows:

 

Week_IndexStart_Date
002/04/2018
109/04/2018
216/04/2018
323/04/2018
430/04/2018

 

Where a new record has been inserted with 'Week_Index' = 0 and 'Start_Date' = min of all existing dates - 7 days.

 

I have the following code, but the syntax is not quite right:

 

Custom1 = Table.InsertRows(#"Renamed Columns",2, { [Week_Index = 0, Start_Date = List.Min([Start_Date]-7)] })

 

Can anyone help, please?

 

Thanks,

 

Matty

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Interkoubess Established Member
Established Member

Re: Insert row with reference to an existing row - Power Query...

Hi @Matty,

 

Please change your formula by the following one:

Custom1=Table.InsertRows(#"Renamed Columns",2, { [Week_Index = 0, Start_Date = List.Min(#"Renamed Columns"[Start_Date])+#duration(-7,0,0,0))] })

Hope it helps....

 

 

Ninter

View solution in original post

2 REPLIES 2
Highlighted
Interkoubess Established Member
Established Member

Re: Insert row with reference to an existing row - Power Query...

Hi @Matty,

 

Please change your formula by the following one:

Custom1=Table.InsertRows(#"Renamed Columns",2, { [Week_Index = 0, Start_Date = List.Min(#"Renamed Columns"[Start_Date])+#duration(-7,0,0,0))] })

Hope it helps....

 

 

Ninter

View solution in original post

Matty Regular Visitor
Regular Visitor

Re: Insert row with reference to an existing row - Power Query...

Hi Ninter,

 

Thanks for that - it worked as desired.

 

Cheers,

 

Matty

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors
Top Kudoed Authors