add new lines in power query

richard_first

New Member
Joined
Dec 13, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
i will have a table which i have already loaded from power query, but the number in the batch column is discontiguous. what I want power query do is to add new lines and fill in the missing number in the column batch to make the sequence contiguously and fill in the batch_result with "successfully".
batchbatch_result
515​
CANCELLED
506​
CANCELLED
501​
CANCELLED
497​
CANCELLED
483​
CANCELLED
476​
CANCELLED
466​
CANCELLED
461​
CANCELLED
444​
CANCELLED

thank you in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
How about showing us your source table and your Mcode so we can see what you have done and what needs to happen to get your expected results. Additionally for the inserted batches, what do you expect the batch result to state. We are excel helpers here, not mind readers.
 
Upvote 0
How about showing us your source table and your Mcode so we can see what you have done and what needs to happen to get your expected results. Additionally for the inserted batches, what do you expect the batch result to state. We are excel helpers here, not mind readers.
hi alansidman,
thank you for your reply.
i am sorry i cannot attach the source table, because i load it from a table in the intranet of my company.
the table i mentioned above is the result i have loaded from the internal table.
in the source table the numbers in the batch column are discontiguous.
what i want power query do is to change the table as following:

batchbatch_result
515​
CANCELLED
514​
successful
513​
successful
512​
successful
511​
successful
510​
successful
509​
successful
508​
successful
507​
successful
506​
CANCELLED
505​
successful
504​
successful
503​
successful
502​
successful
501​
CANCELLED
500​
successful
499​
successful
498​
successful
497​
CANCELLED
496​
successful
495​
successful
494​
successful
493​
successful
492​
successful
491​
successful
490​
successful
489​
successful
488​
successful
487​
successful
486​
successful
485​
successful
484​
successful
483​
CANCELLED
 
Upvote 0
try
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    List = {444..515},
    C2T = Table.FromList(List, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Ren = Table.RenameColumns(C2T,{{"Column1", "batch"}}),
    SortD = Table.Sort(Ren,{{"batch", Order.Descending}}),
    Join = Table.NestedJoin(SortD,{"batch"},Source,{"batch"},"Table1",JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Join, "Table1", {"batch_result"}, {"batch_result"}),
    Replace = Table.ReplaceValue(Expand,null,"successfully",Replacer.ReplaceValue,{"batch_result"})
in
    Replace
batchbatch_resultbatchbatch_result
515CANCELLED515CANCELLED
506CANCELLED514successfully
501CANCELLED513successfully
497CANCELLED512successfully
483CANCELLED511successfully
476CANCELLED510successfully
466CANCELLED509successfully
461CANCELLED508successfully
444CANCELLED507successfully
506CANCELLED
505successfully
504successfully
503successfully
502successfully
501CANCELLED
500successfully
499successfully
498successfully
497CANCELLED
496successfully
495successfully
494successfully
493successfully
492successfully
491successfully
490successfully
489successfully
488successfully
487successfully
486successfully
485successfully
484successfully
483CANCELLED
482successfully
481successfully
480successfully
479successfully
478successfully
477successfully
476CANCELLED
475successfully
474successfully
473successfully
472successfully
471successfully
470successfully
469successfully
468successfully
467successfully
466CANCELLED
465successfully
464successfully
463successfully
462successfully
461CANCELLED
460successfully
459successfully
458successfully
457successfully
456successfully
455successfully
454successfully
453successfully
452successfully
451successfully
450successfully
449successfully
448successfully
447successfully
446successfully
445successfully
444CANCELLED
 
Upvote 0
or more flexible
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    cnt = Table.RowCount(Source)-1,
    First = Source[batch]{0},
    Last = Source[batch]{cnt},
    List = {Last..First},
    C2T = Table.FromList(List, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Ren = Table.RenameColumns(C2T,{{"Column1", "batch"}}),
    SortD = Table.Sort(Ren,{{"batch", Order.Descending}}),
    Join = Table.NestedJoin(SortD,{"batch"},Source,{"batch"},"Table1",JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Join, "Table1", {"batch_result"}, {"batch_result"}),
    Replace = Table.ReplaceValue(Expand,null,"successfully",Replacer.ReplaceValue,{"batch_result"})
in
    Replace
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table26"]}[Content],
    toRows=Table.ToRows(Source),
    res=List.Accumulate(
                            List.Skip(toRows),
                            {toRows{0}},
                            (x,y)=>
                                    x&List.Transform({1..List.Last(x){0}-y{0}-1},each {List.Last(x){0}-_,"Successful"})&{y}
                       )
in
    #table({"Batch","Result"},res)
 
Upvote 0

Forum statistics

Threads
1,223,754
Messages
6,174,311
Members
452,554
Latest member
Louis1225

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top