简体   繁体   English

在 power bi 中展开包含列表和日期的列

[英]Expand column which has list and date in power bi

I have a column which has a list of dates and dates.我有一个包含日期和日期列表的列。

在此处输入图像描述

在此处输入图像描述 I need to expand the column so that the list of dates under list gets expanded along with the dates in the column.我需要扩展该列,以便列表下的日期列表与列中的日期一起扩展。

I have used the below code and getting the "Expression.Error: We cannot convert a value of type List to type Table. Details: Value=[List] Type=[Type]"我使用了下面的代码并得到了“Expression.Error:我们无法将 List 类型的值转换为 Table 类型。详细信息:Value=[List] Type=[Type]”

Table.TransformColumns([Custom],{{[Custom],each if Value.Is(_,type list) then _ else {_}}})

Code to generate the list生成列表的代码

= Table.AddColumn(#"Removed Blank Rows", "New end date", each let StDt = [#"Grant date #(lf)(dd/mm/yyyy)"],

Code to expand the list as per your code.根据您的代码扩展列表的代码。

Table.AddColumn(#"Added Custom", "Custom.1", each Table.TransformColumns([New end date]{{[New end date],each if Value.Is(_,type list) then _ else {_}}}))

This converts non-list rows to lists so that the arrow option shows up这会将非列表行转换为列表,以便显示箭头选项

x = Table.TransformColumns(#"PriorStepName", {{"Custom", each if Value.Is(_, type list) then _ else {_} }} )

then use the arrows atop the column to expand.然后使用列顶部的箭头展开。 Then change type然后改变类型

Before picture:前图:

在此处输入图像描述

after picture图片后

在此处输入图像描述

full sample code完整示例代码

let Source =  #table({"a"}, {{"10/1/2020"},{"4/1/2020"},{"6/1/2020"},{"1/1/2020"},{"10/4/2020"},{"10/8/2020"}}),
z = {"5/31/2021","5/15/2020","3/14/2019"},
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each if [Index]<2 then z else [a], type any),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
// prior is just to set up sample data
x = Table.TransformColumns(#"Removed Other Columns", {{"Custom", each if Value.Is(_, type list) then _ else {_} }} ),
#"Expanded Custom" = Table.ExpandListColumn(x, "Custom"),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type date}})
in #"Changed Type"

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

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