LOOKUP(2,1 WITH POWER QUERY

roykana

Active Member
Joined
Mar 8, 2018
Messages
311
Office Version
  1. 2010
Platform
  1. Windows
Dear all master,

I want to bring up the date and last value of the transaction with the power query.

there are hundreds of thousands of records if I use the formula to make it very slow.please solution with power query

LOOKUP 2,1 WITH POWER QUERY.xlsx
ABCDEFGHIJKLMNOP
1PNMITMITCUNIQTYCIUNOD BLC BRANDOPTIONDATESACITEMDISCPCCHECK DATECHECK ITEMDISCPCstatus
21000TESTLA R 10001000Pcs1400000140,000TESTLAYES04-01-22A.03.01.029.05210   
31001TESTLU R 10011001Pcs1400000240,000TESTLUYES05-01-22A.03.01.029.05220   
41002TESTLA R 10021002Pcs1450000345,000TESTLAYES06-01-22A.03.01.029.0521504/01/202210ns
51003TESTLU R 10031003Pcs1600000460,000TESTLUYES07-01-22A.03.01.029.0521005/01/202220ns
61004TESTLA R 10041004Pcs1700000570,000TESTLAYES08-01-22A.03.01.029.0521506/01/202215s
DB
Cell Formulas
RangeFormula
N2:N6N2=IFERROR(LOOKUP(2,1/([SAC]=$L2)/([BRAND]=$I2)/([DATE]<$K2),[DATE]),"")
O2:O6O2=IFERROR(LOOKUP(2,1/([SAC]=$L2)/([BRAND]=$I2)/([DATE]<$K2),[ITEMDISCPC]),"")
P2:P6P2=IF([@[CHECK ITEMDISCPC]]="","",IF([@ITEMDISCPC]=[@[CHECK ITEMDISCPC]],"s","ns"))


thanks
roykana
 

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.
Please try

1 NestedJoin
Power Query:
let
    Source = Table.Buffer(Excel.CurrentWorkbook(){[Name="Table1"]}[Content]),
    MergedQueries = Table.NestedJoin(Source, {"BRAND", "SAC"}, Table1, {"BRAND", "SAC"}, "Table1", JoinKind.LeftOuter),
    Last = Table.AddColumn(MergedQueries, "Last", each Table.Last(Table.SelectRows([Table1], (x)=> x[DATE] < [DATE]))),
    ExpLast = Table.ExpandRecordColumn(Last, "Last", {"DATE", "ITEMDISCPC"}, {"C_DATE", "C_ITEMDISCPC"}),
    AStatus = Table.AddColumn(ExpLast, "C_Status", each if [C_ITEMDISCPC] = null then null else if [C_ITEMDISCPC]=[ITEMDISCPC] then "s" else "ns")
in
    AStatus

2 SelectRows
Power Query:
let
    Source = Table.Buffer(Excel.CurrentWorkbook(){[Name="Table1"]}[Content]),
    Latest = Table.AddColumn(Source, "Last", each    Table.Last(Table.SelectRows(Source, (s)=> s[SAC]=[SAC] and s[BRAND]=[BRAND] and s[DATE]<[DATE] ) )),
    ExpLast = Table.ExpandRecordColumn(Latest, "Last", {"DATE", "ITEMDISCPC"}, {"C_DATE", "C_ITEMDISCPC"}),
    AStatus = Table.AddColumn(ExpLast, "C_Status", each if [C_ITEMDISCPC] = null then null else if [C_ITEMDISCPC]=[ITEMDISCPC] then "s" else "ns")
in
    AStatus

Not sure which one is faster, my guess is NestedJoin.
 
Upvote 0
Please try

1 NestedJoin
Power Query:
let
    Source = Table.Buffer(Excel.CurrentWorkbook(){[Name="Table1"]}[Content]),
    MergedQueries = Table.NestedJoin(Source, {"BRAND", "SAC"}, Table1, {"BRAND", "SAC"}, "Table1", JoinKind.LeftOuter),
    Last = Table.AddColumn(MergedQueries, "Last", each Table.Last(Table.SelectRows([Table1], (x)=> x[DATE] < [DATE]))),
    ExpLast = Table.ExpandRecordColumn(Last, "Last", {"DATE", "ITEMDISCPC"}, {"C_DATE", "C_ITEMDISCPC"}),
    AStatus = Table.AddColumn(ExpLast, "C_Status", each if [C_ITEMDISCPC] = null then null else if [C_ITEMDISCPC]=[ITEMDISCPC] then "s" else "ns")
in
    AStatus

2 SelectRows
Power Query:
let
    Source = Table.Buffer(Excel.CurrentWorkbook(){[Name="Table1"]}[Content]),
    Latest = Table.AddColumn(Source, "Last", each    Table.Last(Table.SelectRows(Source, (s)=> s[SAC]=[SAC] and s[BRAND]=[BRAND] and s[DATE]<[DATE] ) )),
    ExpLast = Table.ExpandRecordColumn(Latest, "Last", {"DATE", "ITEMDISCPC"}, {"C_DATE", "C_ITEMDISCPC"}),
    AStatus = Table.AddColumn(ExpLast, "C_Status", each if [C_ITEMDISCPC] = null then null else if [C_ITEMDISCPC]=[ITEMDISCPC] then "s" else "ns")
in
    AStatus

Not sure which one is faster, my guess is NestedJoin.
@Bo_Ry
Dear Mr. Bo_Ry ,
Thanks for your reply. I tried power query code from you in my actual data very slowly

thanks
roykana
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,718
Members
452,667
Latest member
vanessavalentino83

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