簡體   English   中英

Excel 上的復雜 VLOOKUP

[英]Complicated VLOOKUP on Excel

我正在嘗試分析我在網上商店中保存的同義詞的效率。 我有一個大約 5000 個同義詞的列表,並想在 Excel 的幫助下在 1.000.000 個查詢的列表中查找它們。 問題是,在每個“同義詞單元格”上,我可能有多個由空格分隔的同義詞。 我想在查詢字符串列表中找到這些同義詞。 最終,每當有匹配項時,我希望在引用單元格“VLOOKUP”中找到附加到該同義詞的產品,並將它們一起計算,看看我在同義詞的幫助下獲得了多少銷售額。

希望這個解釋不是太復雜,您可以幫助我在搜索查詢中找到每個同義詞。 如果您對如何更有效地執行此過程有更好的想法,那就更好了。 :-)

這是一些可以很好解釋的示例數據,我要做什么: https://docs.google.com/spreadsheets/d/1UASfryBJ6pQiAqVy8Z6dJ1klJkUzCu4UZZCunjAIDFg/edit?usp=sharing

隨意編輯它,非常感謝! 內斯

為了查找同義詞(在工作表“同義詞”的 B 列中找到,也許你必須像這樣重構工作表“同義詞”:


| synonym | product |

| -------- | -------|

| icecream | cake1  |

| sweets   | cake1  |

之后,您需要將查詢列拆分為多列(每列一個單詞)並在重構的同義詞工作表中查找每個單詞

有了這么多數據,並使用 Excel,我建議使用 Power Query(在 Windows Excel 2010+ 和 O365 中可用)。

  • 讀入查詢表
    • 通過空格分隔符將查詢拆分為單獨的列
    • unpivot 創建查詢詞的單列
  • 讀入同義詞表
  • 通過空格分隔符將同義詞分成單獨的列
  • unpivot 創建單列同義詞
  • 做兩個表的嵌套模糊連接
    • 模糊,因此您可以執行IgnoreCase之類的操作並設置適當的Threshold以允許單個單詞和復數單詞以及查詢中的輕微拼寫錯誤。
  • 重新組合拆分列,創建 output 表

您可能需要根據實際數據調整列拆分器和閾值等內容。 此外,我只允許使用一個同義詞和產品。 列拆分器可以重寫以處理任意數量的列,如果我今天晚些時候有時間我會看看

我試圖評論 M 代碼來解釋事情

請注意代碼第 4 行和第 18 行中的表名。 您可能需要更改這些(或者,如果從外部源讀取它們,則完全更改該行)。

M代碼

粘貼到 PQ 中的高級編輯器中

let

//Read in Query Table and convert to single column of words in query
    Source = Excel.CurrentWorkbook(){[Name="tblQuery"]}[Content],
    #"Changed Type1" = Table.TransformColumnTypes(Source,{{"query", type text}, {"bought", type text}}),

    //add an index column for eventual reconstruction
    #"Add Index" = Table.AddIndexColumn(#"Changed Type1","Index",0,1),
   
    //may need more splits depending on real data
    splitIt = Table.SplitColumn(#"Add Index", "query", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), 
        {"query.1", "query.2", "query.3"}),
    #"Unpivoted Other Columns1" = Table.UnpivotOtherColumns(splitIt, {"Index", "bought"}, "Attribute", "Value"),
    queryTbl = Table.RemoveColumns(#"Unpivoted Other Columns1",{"Attribute"}),

    //Read in synonym table
    //unpivot to convert to two column table
    Source2 = Excel.CurrentWorkbook(){[Name="tblSyno"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source2,{{"product", type text}, {"query-synonym", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "query-synonym", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"query-synonym.1", "query-synonym.2", "query-synonym.3"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"query-synonym.1", type text}, {"query-synonym.2", type text}, {"query-synonym.3", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type2", {"product"}, "Attribute", "Value"),
    synoTbl = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),

    //combine tables based on synonyms
    //combTbl = Table.NestedJoin(queryTbl,"Value",synoTbl,"Value","Joined",JoinKind.LeftOuter),
    combTbl = Table.FuzzyNestedJoin(queryTbl,"Value",synoTbl,"Value","Joined",JoinKind.LeftOuter,
            [IgnoreCase=true, Threshold=0.9]),

    //extract the synonym
    #"Added Custom" = Table.AddColumn(combTbl, "Synonym", each try Table.Column([Joined],"Value"){0} 
                            otherwise null),
    #"Added Custom4" = Table.AddColumn(#"Added Custom", "Attached Product", each try Table.Column([Joined],"product"){0}
otherwise null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom4",{"Joined"}),

    //Recombine by the Index column to recreate the query
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Index"}, {{"Group", each _, type table [bought=nullable text, Index=number, Value=text, Joined=table, Synonym=nullable text]}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Grouped Rows",{"Index"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns1", "query", each Table.Column([Group],"Value")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom1", 
        {"query", each Text.Combine(List.Transform(_, Text.From), " "), type text}),
    
    //extract the "bought" column from the group table
    //if there might be more than one product in 
        //the "bought" column, need to change this
    #"Added Custom2" = Table.AddColumn(#"Extracted Values", "bought", each 
        List.Distinct(Table.Column([Group],"bought")){0}),

    //extract the Matched Synonym column
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Matched Synonym", each List.RemoveNulls(Table.Column([Group],"Synonym")){0}),

    //extract the Attached Product column
    #"Added Custom5" = Table.AddColumn(#"Added Custom3", "Attached Product", each List.RemoveNulls(Table.Column([Group],"Attached Product")){0}),
    #"Removed Columns2" = Table.RemoveColumns(#"Added Custom5",{"Group"})
in
    #"Removed Columns2"

同義詞表

在此處輸入圖像描述

結果

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM