简体   繁体   English

Power BI - 如何组合来自 Power Query 中另一个查询(表)的列中的所有值

[英]Power BI - How to combine all the values in a column from another query (table) in Power Query

I'm trying to write a power query to where I can join all the values of a column from another query (table) into a single line.我正在尝试编写一个强大的查询,我可以将来自另一个查询(表)的列的所有值连接到一行中。

Example:例子:

Table from Query 1来自查询 1 的表

日期

Outcome: I want it to return a text like:结果:我希望它返回如下文本:

[2019-09],[2019-10],[2019-11],[2019-12],[2020-01],[2020-02] [2019-09],[2019-10],[2019-11],[2019-12],[2020-01],[2020-02]

I'm trying to put this in my other query, within a JSON code, where the text combine function is (Value).我试图将它放在我的另一个查询中,在 JSON 代码中,其中文本组合函数是 (Value)。

          {""DataModelName"":""[AllStreams].[Month Year]"",
            ""Caption"":"""&Date.ToText( DateTime.Date( Date.AddDays(DateTimeZone.UtcNow(),0) ) , "yyyy-MM")&""",
            ""Value"":""[" 
                & Text.Combine(Table.SelectColumns(FilterList_PV)[Date]), "" ) & "]"",
            ""Operand"":0,
            ""UnionGroup"":""""}

Let me know if this is possible!让我知道这是否可能! Thanks!谢谢!

you can do this with one big step, but shown here in smaller pieces你可以迈出一大步来做到这一点,但这里以较小的部分显示

Assuming column in question is named Date假设有问题的列名为Date

Add a column we can use to group on, all with same value添加一个我们可以用来分组的列,所有列都具有相同的值

Add column that converts each date into text surrounded by [] showing year and month添加将每个日期转换为由 [] 包围的文本的列,显示年和月

Group on the first added column, combining all row values在第一个添加的列上分组,组合所有行值

Remove extra column删除多余的列

#"Added Custom" = Table.AddColumn(#"PriorStep", "Custom", each "[" & Text.From(Date.Year([Date])) & "-" & Text.PadStart(Text.From(Date.Month([Date])),2,"0") &"]"),
#"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 0, 0),
#"Grouped Rows" = Table.Group(#"Added Index", {"Index"}, {{"Count", each Text.Combine(  List.Transform([Custom], Text.From), ","), type text}}),
#"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Index"})

这是另一种方式: Text.Combine(List.Transform(Table[Column], Text.From),",")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM