如何使用Microsoft Power Bi计算单词出现的总次数?

3
我有一个包含单词列表的表格,我想知道如何使用DAX语言实现以下示例:

ID Items
1 苹果
2 香蕉
3 苹果,香蕉
4 橙子,苹果
Items Total
苹果 3
香蕉 2
橙子 1

问题在于有些行包含多个条目,而使用Count函数仅计算列表中的第一个条目。

我不想要的输出结果:

Items Total
苹果 2
香蕉 1
橙子 1

我当前的解决方法是将列拆分,使用透视表,然后进行计数。


您可以基于源表创建一个单独的表格,其中您将始终拥有按项目计数的数据。 - mkRabbani
1个回答

1
你可以基于源表格创建一个单独的表格,其中你将始终拥有每个项目的计数。使用下面的高级查询代码为你的新表格。只需在代码中更改源表格名称为你的原始表格名称即可。
let
    Source = your_table_name,
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Items", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Items"),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Items", type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Items", Text.Trim, type text}}),
    #"Grouped Rows" = Table.Group(#"Trimmed Text", {"Items"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"

这里是最终输出 -

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接