如何从电源查询中的另一个表中查找值?

发布于 2025-02-08 08:21:04 字数 601 浏览 1 评论 0原文

​基于dim_strategy表。我的挑战是,每行可能会出现超过1个策略代码,因此我想使用+作为定界符,将不同的策略名称组合在data表中。

这是data表中所需的输出:

”在此处输入图像说明”

enter image description here

enter image description here

I want to transform the strategy code number in my Strategy Code column (Data table) into strategy name based on the dim_strategy table. My Challenge is there can be more than 1 strategy code appear in each row and hence I want to use + as the delimiter to combine different strategy name in Data table.

This is the desired output in Data table:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋日私语 2025-02-15 08:21:04

此查询将为您实现。您将需要更改表源的任何源,但是其余的步骤应该完全相同。

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"No.", Int64.Type}, {"Strategy Code", type text}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Strategy Code", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Strategy Code"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Strategy Code", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type1", {"Strategy Code"}, dim_strategy, {"Strategy Code"}, "dim_strategy", JoinKind.LeftOuter),
    #"Expanded dim_strategy" = Table.ExpandTableColumn(#"Merged Queries", "dim_strategy", {"Strategy"}, {"Strategy"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded dim_strategy",{"Strategy Code"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"No."}, {{"Stretagy Name", each Text.Combine([Strategy], " + "), type nullable text}})
in
    #"Grouped Rows"

This query will achieve that for you. You will need to change the source for whatever your table source is but the rest of the steps should be exactly the same.

enter image description here

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"No.", Int64.Type}, {"Strategy Code", type text}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Strategy Code", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Strategy Code"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Strategy Code", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type1", {"Strategy Code"}, dim_strategy, {"Strategy Code"}, "dim_strategy", JoinKind.LeftOuter),
    #"Expanded dim_strategy" = Table.ExpandTableColumn(#"Merged Queries", "dim_strategy", {"Strategy"}, {"Strategy"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded dim_strategy",{"Strategy Code"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"No."}, {{"Stretagy Name", each Text.Combine([Strategy], " + "), type nullable text}})
in
    #"Grouped Rows"
衣神在巴黎 2025-02-15 08:21:04

或者,您可以添加一个列

let  Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Strategy Name", each Text.Combine(
    List.Transform(Text.Split([Strategy Code],","), each  
    dim_strategy[Strategy]{List.PositionOf(dim_strategy[Strategy Code],Number.From(_))}
),", "))
in  #"Added Custom"

”在此处输入图像描述”

它将策略代码转换为列表,然后转换为数值列表,在DIM_STRATEGY策略码中找到该列表的位置,然后拉动相应的策略列并重新组合列表进入文本

列表。Bufferdim_strategy2 [策略代码]作为较早的步骤,如果数据集很大

Or you could add a column

let  Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Strategy Name", each Text.Combine(
    List.Transform(Text.Split([Strategy Code],","), each  
    dim_strategy[Strategy]{List.PositionOf(dim_strategy[Strategy Code],Number.From(_))}
),", "))
in  #"Added Custom"

enter image description here

It converts the Strategy Code to a list, then to numerical list, finds the position of that in the dim_strategy Strategy Code column, then pulls the corresponding Strategy column and recombines the list into text

List.Buffer dim_strategy2[Strategy Code] as an earlier step if dataset is large

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文