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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
KuntalSingh
Helper V
Helper V

Data in two column matching

 

if both the ZA and RE rows  in Document Type column should be marked as match if the Text column of the ZA document has a number that exactly matches the field for the RE invoice Reference number column (Sample has been shared)in Bold

 

ScriptsVendorVendorNameCompanyCodeFiscalYearDocumentTypeDocumentDatePostingKeyPostingDateDocumentNumberReferenceAmountindoccurrDocumentcurrencyAmountinlocalcurrencyLocalCurrencyTextNetduedate
S(87-100)-42003232794 US282024ZA31-01-20243124-02-2024550048568234467685-141107.8USD-141107.8USD149173/31/2024
S(87-100)-42003232794 US292024RE31-01-20243115-03-2024510092208414917-141107.8USD-141107.8USD 3/31/2024
S(25-60)-12003188715 US012024RE04-10-20233126-08-202451001955026727721V-95.51USD-95.51USD 12/3/2023
S(25-60)-12004015722FISHER SCIENTIFICUS012023RE04-10-20233110-10-202351010730376727721V-95.51USD-95.51USD 12/3/2023
S(25-60)-12003871958CINTAS CORPORATION NUS052024RE03-07-20243126-08-202451007215024197836999-125.37USD-125.37USDVR:Pay-as-billed9/1/2024
S(25-60)-12000029014CINTAS CORPORATION 100US052024RE03-07-20243125-07-202451014000934197836999-125.37USD-125.37USDVR:Pay-as-billed9/1/2024
S(25-60)-12000028457ARAMARK UNIFORM AND CAREER APPARELUS052024RE09-07-20243126-08-202451007160025630471355-128.4USD-128.4USDVR:Pay-as-billed9/22/2024
S(25-60)-12004363146VESTIS GROUP, INC.US052024RE09-07-20243105-08-202451013061405630471355-128.4USD-128.4USDVR:Pay-as-billed9/22/2024
S(25-60)-12004235596G&G OUTFITTERS INCUS052024RE09-02-20243126-08-20245100153099242772-166.75USD-166.75USD 4/9/2024
S(25-60)-12000011986G&G OUTFITTERS INCUS052024RE09-02-20243116-02-20245100042734242772-166.75USD-166.75USD 4/9/2024
S(25-60)-12003871958CINTAS CORPORATION NUS012024RE02-01-20243126-08-202451018370004178789859-205.94USD-205.94USD 3/2/2024
S(25-60)-12000029014CINTAS CORPORATION 100US012024RE02-01-20243106-08-202451005247404178789859-205.94USD-205.94USD 3/2/2024
S(25-60)-12003871958CINTAS CORPORATION NUS012024RE16-01-20243126-08-202451000625094180383750-209.39USD-209.39USD 3/16/2024
S(25-60)-12000011956CINTAS CORPORATION NO 2US012024RE16-01-20243102-08-202451009005244180383750-209.39USD-209.39USD 3/16/2024
S(25-60)-12003871958CINTAS CORPORATION NUS012024RE30-01-20243126-08-202451018640004181744364-216.43USD-216.43USD 3/30/2024
S(25-60)-12000029014CINTAS CORPORATION 100US012024RE30-01-20243106-08-202451012055124181744364-216.43USD-216.43USD 3/30/2024
S(25-60)-22000014020NYSCO PRODUCTS LLCUS052024RE31-01-20222126-08-202451008240020236725-IN91.4USD91.4USDVR:Full Accrual4/1/2022
S(25-60)-22000014020NYSCO PRODUCTS LLCUS052024RE31-01-20223114-06-202451010235450236725-IN-91.4USD-91.4USD  
S(25-60)-22000022228W W GRAINGERUS012024RE22-03-20232126-08-202451003365119648709799217.97USD217.97USDVR:Pay-as-billed7/20/2023
S(25-60)-22000022228W W GRAINGERUS012024RE22-03-20233110-05-202451012950149648709799-217.97USD-217.97USDVR:Pay-as-billed7/20/2023
S(25-60)-22000022228W W GRAINGERUS012024RE15-05-20232126-08-202451018430009706842102144.47USD144.47USDVR:Pay-as-billed9/12/2023
7 REPLIES 7
dufoq3
Super User
Super User

Hi @KuntalSingh, try this:

 

Output

dufoq3_0-1725611682107.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("vZdNb9swDIb/itHTBtQ2SZH62M1Ik85Yawd2smFfh67bYUBOG3rYv58kN43tOWnQpguCwJRh+dHLVxTz+fNZ+8qaFAFep3x2fkYAihQZFwL/Xbdk4zCFgU+F/1GYAqb3IwrDXU6BtiMiAGxFWwq3mbXRVvxliowIJrNx1ovJEWSHJjyWK8zjfF/PjyB0O8JmPkmIkoJ6IPRzOSKw3HvlMXgTZCSp9mB4D4bWGpQtGOAIjHOE8LR6UE6nYPtc6Lx+QTltyBjC9wHESSa44xqGYQ2Uq27aKSgGFENhzkXZvp03STsr59WqXJSzAaXaS+nD3Yin9KooUOaklMoL5yRoPSurVdEms7pZ1k2xKusqqTpQGec5N/nAh2M1PVqnJqMzVmnnXEwsSRbxt4kexu+bN8ubP+nN7/Tbz83mx3c/5PIDWQcgB8jT6J7iSHhvUdODR/YTO/Uf4C1LeL5oiuuieZesq3JRN9dJUV0ks6KZe8cUy6W/uJpeiHs0C6ghZkG0AjaopKsHZDPur6MfTi6DaP86WGmFrMOj83ZVtsllU6+X50lZzbLjuCW3eU9+Bdqn4KWpyU/rAvXllzsvkr5M6vVqUa5W86YN7PvQ6bDkKAqiXYjDBo2kWmdGeuTDOO57d8gniM4+mxR1/6jwpF4Co/iUpMdUknFhpu0W2SMoWmUg7mRGY411VuJmJJDM9ewwiuM2P5D+4yrHY7B6YFwQYsMnR32KqiHZo05hbFTQJOAirPXvUEagg3OZcn3YQRxhUT/iVtF7aOuEjgYeauuivCfHfYq4Ch4TF63mrWktGvYlkiMd6oxVj3YYR1oFp3btv7xD36I3pCCdjpYerMBAAar62M7qZNnUF+vZqk2urvbUrIf2Mc4waVtL3B1pvp3xPZCkZciSw95ZMAj8wbC422yS4vb2193NJpawuInpJZi7Suubct13g0cVljFzOuAcRuE7jUf+E+z6IfngD9qirC7nzZ5iRfedt9orplJaMNxxmq0BZ7qTC03mdn3NKJw4acNpPtFfPpd52wHLwKtOuh0wQE5HkOP4RaHDXxw5KDRaVl09cAa0ZcJoYWTOeAc5Cqf7Sbpn/voX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Scripts = _t, Vendor = _t, VendorName = _t, CompanyCode = _t, FiscalYear = _t, DocumentType = _t, DocumentDate = _t, PostingKey = _t, PostingDate = _t, DocumentNumber = _t, Reference = _t, Amountindoccurr = _t, Documentcurrency = _t, Amountinlocalcurrency = _t, LocalCurrency = _t, Text = _t, Netduedate = _t]),
    ZA_Text = List.Buffer(Table.SelectRows(Source, each ([DocumentType] = "ZA"))[Text]),
    RE_Reference = List.Buffer(Table.SelectRows(Source, each ([DocumentType] = "RE"))[Reference]),
    StepBack = Source,
    Ad_Check = Table.AddColumn(StepBack, "Check", each 
        if [DocumentType] = "ZA" then 
            if List.Contains(RE_Reference, [Text]) then "match" else null else 
        if List.Contains(ZA_Text, [Reference]) then "match" else null, type text)
in
    Ad_Check

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

KuntalSingh
Helper V
Helper V

Thanks for prompt reply!

took much time to load .it keeps on loading normal file size is 5MB but while loading it is more than 1.5 GB still keeps loading

wdx223_Daniel
Super User
Super User

NewStep=let ref=List.Buffer(YourTable[Reference]),txt=List.Buffer(YourTable[Text]) in Table.AddColumn(YourTable,"MatchMark",each if [DocumentType]="ZA" then List.Contains(ref,[Text]) else List.Contains(txt,[Reference]))

Thanks for relpy

It is not given the desired output ask is number in ZA type document have the same number in RE type document or vice versa as highlighte in black in given sample

Anonymous
Not applicable

Hi @KuntalSingh ,

Please try this M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("vZdNb9swDIb/itHTBtQ2SZH62M1Ik85Yawd2smFfh67bYUBOG3rYv58kN43tOWnQpguCwJRh+dHLVxTz+fNZ+8qaFAFep3x2fkYAihQZFwL/Xbdk4zCFgU+F/1GYAqb3IwrDXU6BtiMiAGxFWwq3mbXRVvxliowIJrNx1ovJEWSHJjyWK8zjfF/PjyB0O8JmPkmIkoJ6IPRzOSKw3HvlMXgTZCSp9mB4D4bWGpQtGOAIjHOE8LR6UE6nYPtc6Lx+QTltyBjC9wHESSa44xqGYQ2Uq27aKSgGFENhzkXZvp03STsr59WqXJSzAaXaS+nD3Yin9KooUOaklMoL5yRoPSurVdEms7pZ1k2xKusqqTpQGec5N/nAh2M1PVqnJqMzVmnnXEwsSRbxt4kexu+bN8ubP+nN7/Tbz83mx3c/5PIDWQcgB8jT6J7iSHhvUdODR/YTO/Uf4C1LeL5oiuuieZesq3JRN9dJUV0ks6KZe8cUy6W/uJpeiHs0C6ghZkG0AjaopKsHZDPur6MfTi6DaP86WGmFrMOj83ZVtsllU6+X50lZzbLjuCW3eU9+Bdqn4KWpyU/rAvXllzsvkr5M6vVqUa5W86YN7PvQ6bDkKAqiXYjDBo2kWmdGeuTDOO57d8gniM4+mxR1/6jwpF4Co/iUpMdUknFhpu0W2SMoWmUg7mRGY411VuJmJJDM9ewwiuM2P5D+4yrHY7B6YFwQYsMnR32KqiHZo05hbFTQJOAirPXvUEagg3OZcn3YQRxhUT/iVtF7aOuEjgYeauuivCfHfYq4Ch4TF63mrWktGvYlkiMd6oxVj3YYR1oFp3btv7xD36I3pCCdjpYerMBAAar62M7qZNnUF+vZqk2urvbUrIf2Mc4waVtL3B1pvp3xPZCkZciSw95ZMAj8wbC422yS4vb2193NJpawuInpJZi7Suubct13g0cVljFzOuAcRuE7jUf+E+z6IfngD9qirC7nzZ5iRfedt9orplJaMNxxmq0BZ7qTC03mdn3NKJw4acNpPtFfPpd52wHLwKtOuh0wQE5HkOP4RaHDXxw5KDRaVl09cAa0ZcJoYWTOeAc5Cqf7Sbpn/voX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Scripts = _t, Vendor = _t, VendorName = _t, CompanyCode = _t, FiscalYear = _t, DocumentType = _t, DocumentDate = _t, PostingKey = _t, PostingDate = _t, DocumentNumber = _t, Reference = _t, Amountindoccurr = _t, Documentcurrency = _t, Amountinlocalcurrency = _t, LocalCurrency = _t, Text = _t, Netduedate = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Scripts", type text}, {"Vendor", Int64.Type}, {"VendorName", type text}, {"CompanyCode", type text}, {"FiscalYear", Int64.Type}, {"DocumentType", type text}, {"DocumentDate", type text}, {"PostingKey", Int64.Type}, {"PostingDate", type text}, {"DocumentNumber", Int64.Type}, {"Reference", type text}, {"Amountindoccurr", type number}, {"Documentcurrency", type text}, {"Amountinlocalcurrency", type number}, {"LocalCurrency", type text}, {"Text", type text}, {"Netduedate", type date}}),
    MergedTables = Table.NestedJoin(#"Changed Type", {"Text"}, #"Changed Type", {"Reference"}, "NewColumn", JoinKind.FullOuter),
    ExpandedTables = Table.ExpandTableColumn(MergedTables, "NewColumn", {"DocumentType", "Reference", "Text"}, {"DocumentType1", "Reference1", "Text1"}),
    CustomColumn = Table.AddColumn(ExpandedTables, "MatchCheck", each if [DocumentType] = "ZA" and [DocumentType1] = "RE" and [Text] = [Reference1] then "Match"
                                   else if [DocumentType1] = "ZA" and [DocumentType] = "RE" and [Text1] = [Reference] then "Match"
                                   else null),
    FinalTable = Table.RemoveColumns(CustomColumn,{"DocumentType1", "Reference1", "Text1"}),
    #"Filtered Rows" = Table.SelectRows(FinalTable, each [Scripts] <> null),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each let a=[Scripts],
b=[Vendor],
c=Table.RowCount(Table.SelectRows(#"FinalTable",each [Scripts]=a and [Vendor]=b and [MatchCheck]<>null)) 
in if c>0 then "Match" else null)
in
    #"Added Custom"


Just put all of it into the Advanced Editor, and the final output is as below:

vjunyantmsft_0-1725263488120.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Solution is correct, However data is keep on loading more than 9 hours and data size reaches 22 GB so it is not feasible.

Can you please help me  to apply excel formula in power query 

IF(LEFT(NewColumn,2)="RE",COUNTIFS(NewColumn,SUBSTITUTE(NewColumn,"RE","ZA")),IF(LEFT(NewColumn,2)="ZA",COUNTIFS(NewColumn,SUBSTITUTE(NewColumn,"ZA","RE")),""))

Can any one please help. Why size is increase from MB to 22 GB on last step

 

#"Added Custom" = Table.AddColumn(step, "Custom", each let a=[Reference],
b=[Text],
c=Table.RowCount(Table.SelectRows(#"FinalTable",each [Reference]=a and [Text]=b and [MatchCheck]<>null))
in if c>0 then "Match" else null)
in
#"Added Custom"

 

Complete code is 

let
Source = Excel.Workbook(File.Contents("C:\Users\KUNTALSINGH\Box\PepsiCo - NA Process Session\ACL_Input.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Scripts", type text}, {"Vendor", Int64.Type}, {"VendorName", type text}, {"BusinessArea", type any}, {"CompanyCode", type text}, {"FiscalYear", Int64.Type}, {"DocumentType", type text}, {"DocumentDate", type date}, {"PostingKey", Int64.Type}, {"PostingDate", type date}, {"DocumentNumber", Int64.Type}, {"Reference", type text}, {"Amountindoccurr", type number}, {"DocumentCurrency", type text}, {"Amountinlocalcurr", type number}, {"LocalCurrency", type text}, {"ClearingDocument", Int64.Type}, {"ClearingDate", type text}, {"Text", type text}, {"NetDueDate", type text}}),
#"Filtered Rows2" = Table.SelectRows(#"Changed Type", each ([DocumentType] = "RE" or [DocumentType] = "ZA")),
MergedTables = Table.NestedJoin(#"Filtered Rows2", {"Text"}, #"Filtered Rows2", {"Reference"}, "NewColumn", JoinKind.FullOuter),
ExpandedTables = Table.ExpandTableColumn(MergedTables, "NewColumn", {"DocumentType", "Reference", "Text"}, {"DocumentType1", "Reference1", "Text1"}),
CustomColumn = Table.AddColumn(ExpandedTables, "MatchCheck", each if [DocumentType] = "ZA" and [DocumentType1] = "RE" and [Text] = [Reference1] then "Match"else if [DocumentType1] = "ZA" and [DocumentType] = "RE" and [Text1] = [Reference] then "Match"
else null),
#"FinalTable" = Table.RemoveColumns(CustomColumn,{"DocumentType1", "Reference1", "Text1"}),
#"Filtered Rows" = Table.SelectRows(#"FinalTable", each [Scripts] <> null),
step = Table.Buffer( #"Filtered Rows" ),
#"Added Custom" = Table.AddColumn(step, "Custom", each let a=[Reference],
b=[Text],
c=Table.RowCount(Table.SelectRows(#"FinalTable",each [Reference]=a and [Text]=b and [MatchCheck]<>null))
in if c>0 then "Match" else null)
in
#"Added Custom"

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.