Forum Discussion
Reduce table in table to columns
- 5 years ago
Hello Anonymous
check out this dynamically solution. It chooses the first column of your single tables that contains the name "value" and uses it's data for the column. Be aware that the source step it's just here to reproduce your scenario. The transformation you can see in the step "CreateListOfValueColumns "
let Source = #table ( type table [Column1=table, 204 = table], { { #table ( type table [Column1.ColumnName= text, Column1.Value= any ], { { "name1", "value1" }, { "name2", "value2" }, { "name3", "value3" } } ), #table ( type table [Column1.ColumnName= text, Column1.Value= any ], { { "name1", "abc" }, { "name2", "abcddd" } } ) } } ), CreateListOfValueColumns = Table.TransformRows ( Source, (rec)=> Table.TransformColumns ( Record.ToTable(rec), { { "Value", (tbl)=> Table.Column(tbl,List.Select(Table.ColumnNames(tbl), each Text.Contains(Text.Upper(_), "VALUE")){0}) } } )[Value] ){0}, CreateFinalTable = Table.FromColumns(CreateListOfValueColumns,Table.ColumnNames(Source)) in CreateFinalTableCopy paste this code to the advanced editor in a new blank query to see how the solution works. If you need to implement it in your data source let me know
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Actually, it is easy to understand.
Maybe this example helps you to understand better, what is the expectation:
I have a result with exactly two result lines.
Now I expand the first colum, so that the stored table there will be included in the table but only with one column.
And I use the column value:
Then I get the two lines in the first column:
Now I expand the second column, because I need data there and not tables:
Now I got 4 lines, instead of two, because for each line the previous line is expanded and that is wrong.
In the end the results will be multiplied, and not just showing the results of the table columns in one table.
I didn't read the last post, but as far as I understand from the first, I propose this idea to you
use/adapt this query
let
colN=Table.ColumnNames(correct),
colnames=List.Transform(Table.ColumnNames(correct[aaa]{0}), each colN{0}&"."&_) &List.Transform(Table.ColumnNames(correct[bbb]{0}), each colN{1}&"."&_),
Source = Table.FromColumns(Table.ToColumns(correct[aaa]{0})&Table.ToColumns(correct[bbb]{0}),colnames)
in
Source
where the table correct is the following:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxMVNJRMgRhQ6VYnWilpKQkIMcIhI3AAhAVxiBsjCRgAsImSFpMQdhUKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [name = _t, val1 = _t, val2 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}, {"val1", Int64.Type}, {"val2", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"name"}, {{"all", each _, type table [name=nullable text, val1=nullable number, val2=nullable number]}}),
#"Transposed Table" = Table.Transpose(#"Grouped Rows"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"aaa", type any}, {"bbb", type any}})
in
#"Changed Type1"
then from this
you get this
and not this which is the "wrong" query