Power query IF above row same below row formula

Tivakaran

Board Regular
Joined
Jul 17, 2021
Messages
64
Office Version
  1. 2019
Platform
  1. Windows
Hi,
I need someone to teach me how to copy previous above or below in Power Query.

OK, I did the vendor name by FILL DOWN function in power query. Problem is GNIX is shown below because that row was blank. I need a way to replicate IF(A2=A3,B2,B3) in power query.

first line is blank so it replaced with GNIX from above....supposely it filled with POOJA because as you see the DOCUMENT no is same..... so I need the blank to be filled with same data with same document number....anyone?

1634124650888.png
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
From blue Table1 this M code creates the green table:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    AddIndex = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    AddConditional = Table.AddColumn(AddIndex, "Custom", each
        let i = _[Index], d = AddIndex[Doc], v = AddIndex[Vendor] in
        try if d{i} = d{i+1} then v{i+1} else v{i} otherwise v{i}),
    RemoveColumns = Table.RemoveColumns(AddConditional,{"Vendor", "Index"}),
    Result = Table.RenameColumns(RemoveColumns,{{"Custom", "Vendor"}})
in
    Result

Book1
ABCDEF
1DocVendorDocVendor
21A1B
31B1B
41B1B
51B1B
62B2C
72C2C
82C2C
92C2C
103C3D
113D3D
123D3D
133D3D
14
Sheet1
 
Upvote 0
From blue Table1 this M code creates the green table:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    AddIndex = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    AddConditional = Table.AddColumn(AddIndex, "Custom", each
        let i = _[Index], d = AddIndex[Doc], v = AddIndex[Vendor] in
        try if d{i} = d{i+1} then v{i+1} else v{i} otherwise v{i}),
    RemoveColumns = Table.RemoveColumns(AddConditional,{"Vendor", "Index"}),
    Result = Table.RenameColumns(RemoveColumns,{{"Custom", "Vendor"}})
in
    Result

Book1
ABCDEF
1DocVendorDocVendor
21A1B
31B1B
41B1B
51B1B
62B2C
72C2C
82C2C
92C2C
103C3D
113D3D
123D3D
133D3D
14
Sheet1
Hi.

I tried this but my excel gives error message AddIndex as unknown function.
 
Upvote 0
If you post your code, I'll take a look.
let
Source = Table.NestedJoin(#"Purchase Lines", {"Document No."}, #"Purchase Orders", {"No."}, "Purchase Orders", JoinKind.LeftOuter),
#"Renamed Columns" = Table.RenameColumns(Source,{{"Unit of Measure Code", "UoM"}}),
#"Expanded Purchase Orders" = Table.ExpandTableColumn(#"Renamed Columns", "Purchase Orders", {"Status", "^Last Modified DateTime", "^GRN Approval Status"}, {"Purchase Orders.Status", "Purchase Orders.^Last Modified DateTime", "Purchase Orders.^GRN Approval Status"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Purchase Orders", each ([#"Purchase Orders.^GRN Approval Status"] = "Open")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Purchase Orders.Status", "Purchase Orders.^GRN Approval Status"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Purchase Orders.^Last Modified DateTime", "Order Date", "Document No.", "^Vendor Name", "No.", "Description", "UoM", "Outstanding Quantity", "Outstanding Amount"}),
#"Removed Columns1" = Table.RemoveColumns(#"Reordered Columns",{"Order Date", "Project Code"}),
#"Renamed Columns1" = Table.RenameColumns(#"Removed Columns1",{{"Purchase Orders.^Last Modified DateTime", "Modified Date"}}),
#"Renamed Columns2" = Table.RenameColumns(#"Renamed Columns1",{{"Quantity", "PO Quantity"}, {"No.", "Item No."}, {"^Vendor Name", "Vendor Name"}}),
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns2","DELIVERY","LEADTIME",Replacer.ReplaceText,{"Description"})
in
#"Replaced Value"
 
Upvote 0
I tried to upload the file but its protected by domain and opening without source file just gives error...
 
Upvote 0
try

Power Query:
let
    Source = Table.NestedJoin(#"Purchase Lines", {"Document No."}, #"Purchase Orders", {"No."}, "Purchase Orders", JoinKind.LeftOuter),
    #"Renamed Columns" = Table.RenameColumns(Source,{{"Unit of Measure Code", "UoM"}}),
    #"Expanded Purchase Orders" = Table.ExpandTableColumn(#"Renamed Columns", "Purchase Orders", {"Status", "^Last Modified DateTime", "^GRN Approval Status"}, {"Purchase Orders.Status", "Purchase Orders.^Last Modified DateTime", "Purchase Orders.^GRN Approval Status"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Purchase Orders", each ([#"Purchase Orders.^GRN Approval Status"] = "Open")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Purchase Orders.Status", "Purchase Orders.^GRN Approval Status"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Purchase Orders.^Last Modified DateTime", "Order Date", "Document No.", "^Vendor Name", "No.", "Description", "UoM", "Outstanding Quantity", "Outstanding Amount"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Reordered Columns",{"Order Date", "Project Code"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns1",{{"Purchase Orders.^Last Modified DateTime", "Modified Date"}}),
    #"Renamed Columns2" = Table.RenameColumns(#"Renamed Columns1",{{"Quantity", "PO Quantity"}, {"No.", "Item No."}, {"^Vendor Name", "Vendor Name"}}),
    #"Replaced Value" = Table.ReplaceValue(#"Renamed Columns2","DELIVERY","LEADTIME",Replacer.ReplaceText,{"Description"}),
    AddIndex = Table.AddIndexColumn(#"Replaced Value", "Index", 0, 1, Int64.Type),
    AddConditional = Table.AddColumn(AddIndex, "Custom", each
        let i = _[Index], d = AddIndex[#"Document No."], v = AddIndex[Vendor Name] in
        try if d{i} = d{i+1} then v{i+1} else v{i} otherwise v{i}),
    RemoveColumns = Table.RemoveColumns(AddConditional,{"Vendor Name", "Index"}),
    Result = Table.RenameColumns(RemoveColumns,{{"Custom", "Vendor Name"}})
in 
    Result

You may need to add a Table.ReorderColumns step at the end
 
Upvote 0
Hi.
Will try on next wednesday as we've started on Public Holiday in here. Thanks in advance! ;)
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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