0

我的表如下所示:

我的桌子看起来像这样

我希望它看起来像这样:

我希望它看起来像:

我做到了:

let    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfL0s/b0sQ4NBjIDnK1DEpNyUkusAzLy81KBIkZAbKwUqxMNZoUGW3v6AWk0RaZghbGxAA==",    BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text)    meta [Serialized.Text = true]) in type table [Column1 = _t, market =    _t, device = _t, userCount = _t, Num = _t]),    #"Changed Type" = Table.TransformColumnTypes(Source,{{"market", type text}, {"device", type text}, {"userCount", Int64.Type}}),    #"Transposed Table" = Table.Transpose(#"Changed Type"),    #"Split Column by Delimiter" = Table.SplitColumn(Table.TransformColumnTypes(#"Transposed Table",    {{"Column1", type text}},    "en-US"),"Column1",Splitter.SplitTextByDelimiter(";",    QuoteStyle.Csv),{"Column1.1", "Column1.2", "Column1.3"}),    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type text}, {"Column1.2", type text},    {"Column1.3", type text}}),    #"Split Column by Delimiter1" = Table.SplitColumn(Table.TransformColumnTypes(#"Changed Type1",    {{"Column2", type text}},    "en-US"),"Column2",Splitter.SplitTextByDelimiter(";",    QuoteStyle.Csv),{"Column2.1", "Column2.2"}),    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Column2.1", type text}, {"Column2.2", type text}}),    #"Transposed Table1" = Table.Transpose(#"Changed Type2"),    #"Filled Down" = Table.FillDown(#"Transposed Table1",{"Column3", "Column4", "Column5", "Column1"}),    #"Changed Type3" = Table.TransformColumnTypes(#"Filled Down",{{"Column4", Int64.Type}, {"Column5", Int64.Type}}),    #"Renamed Columns" = Table.RenameColumns(#"Changed Type3",{{"Column1", "ID"}, {"Column2", "Market"}, {"Column3",    "Device"}, {"Column4", "UserCount"}, {"Column5", "Num"}}) in    #"Renamed Columns"

我想通过用分号保存每个值的顺序来拆分多个列:

USERCOUNT of IN and PC is 2
USERCOUNT of Us and Tablet is 5
USERCOUNT US and PC is blank

当您将 2 行转置为 2 列时,此代码很容易,但如果我不知道我有多少行怎么办?

我想创建一个循环来对每一列执行函数(在第一次转置之后)。

4

1 回答 1

1

您可以使用此代码提供动态解决方案:

let    
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfL0s/b0sQ4NBjIDnK1DEpNyUkusAzLy81KBIkZAbKwUqxMNZoUGW3v6AWk0RaZghbGxAA==",    BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text)    meta [Serialized.Text = true]) in type table [Column1 = _t, market =    _t, device = _t, userCount = _t, Num = _t]),    #"Changed Type" = Table.TransformColumnTypes(Source,{{"market", type text}, {"device", type text}, {"userCount", Int64.Type}}),
    ToLists = Table.TransformColumns(#"Changed Type",{{"market", each Text.Split(_, ";")}, {"device", each Text.Split(_, ";")}}),
    #"Added Custom" = Table.AddColumn(ToLists, "Custom", each Table.FromColumns({[market], [device]})),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"market", "device"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Column1", "Column2"}, {"Market", "Device"})
in
    #"Expanded Custom"
于 2016-12-15T10:04:05.517 回答