Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello to all,
I have this table #1 with columns "Month" and corresponding "Id"
Id | Month |
1 | Jan |
2 | Feb |
3 | Mar |
And this table #2 with columns "Visitors", "Day" and "Month"
Visitors | Day | Month |
100 | 4 | Feb |
135 | 7 | Feb |
400 | 23 | Feb |
900 | 8 | Jan |
123 | 21 | Jan |
342 | 27 | Jan |
782 | 29 | Jan |
322 | 11 | Mar |
134 | 19 | Mar |
I want to have a new column in Table #2 with the corresponding "Id" for each month and show sorted by "Id" and then by "Day" like below:
Id | Visitors | Day | Month |
1 | 900 | 8 | Jan |
1 | 123 | 21 | Jan |
1 | 342 | 27 | Jan |
1 | 782 | 29 | Jan |
2 | 100 | 4 | Feb |
2 | 135 | 7 | Feb |
2 | 400 | 23 | Feb |
3 | 322 | 11 | Mar |
3 | 134 | 19 | Mar |
May someone help me to do this please.
Solved! Go to Solution.
Hi @cgkas ,
@HotChilli , His method is worked and convenient. If you want to implement in Power Query. There is a way you can have a try.
1.Choose Home --> Merge Queries --> choose Left Outer
2.Append the table
3.Reordered column Table1.Id and removed the column Table1.Month . Then you can get the table you want.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMgFit9QkpVgdoIixKZBnjiRiAlZjZIwkZAkWsgBir8Q8iDawvJEhkpCxiRFIyBxJyNwCLGSJrMoIJGQI0uibWAR1AshBhpYwoVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Visitors = _t, Day = _t, Month = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Visitors", Int64.Type}, {"Day", Int64.Type}, {"Month", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Month"}, Table1, {"Month"}, "Table1", JoinKind.LeftOuter),
#"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"Id", "Month"}, {"Table1.Id", "Table1.Month"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Table1",{"Table1.Id", "Visitors", "Day", "Month", "Table1.Month"}),
#"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Table1.Id", Order.Ascending}}),
#"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Table1.Month"})
in
#"Removed Columns"
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @cgkas ,
@HotChilli , His method is worked and convenient. If you want to implement in Power Query. There is a way you can have a try.
1.Choose Home --> Merge Queries --> choose Left Outer
2.Append the table
3.Reordered column Table1.Id and removed the column Table1.Month . Then you can get the table you want.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMgFit9QkpVgdoIixKZBnjiRiAlZjZIwkZAkWsgBir8Q8iDawvJEhkpCxiRFIyBxJyNwCLGSJrMoIJGQI0uibWAR1AshBhpYwoVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Visitors = _t, Day = _t, Month = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Visitors", Int64.Type}, {"Day", Int64.Type}, {"Month", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Month"}, Table1, {"Month"}, "Table1", JoinKind.LeftOuter),
#"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"Id", "Month"}, {"Table1.Id", "Table1.Month"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Table1",{"Table1.Id", "Visitors", "Day", "Month", "Table1.Month"}),
#"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Table1.Id", Order.Ascending}}),
#"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Table1.Month"})
in
#"Removed Columns"
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You need a relationship on Month (it should create automatically)
Then create the column in table2 as
Id = RELATED(Table1[Id])
Hi HotChili,
For Table1 I have this code:
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"Month", type text}}) in #"Changed Type"
and for Table2 this code:
let Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Visitors", Int64.Type}, {"Day", Int64.Type}, {"Month", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Id", each RELATED(Table1[Id])) in #"Added Custom"
I added the custim colum but I receive error in #"Added Custom" step.
Expression.Error: The name 'RELATED' wasn't recognized. Make sure it's spelled correctly.
What is missing and what I´m doing wrong?
Thanks
You are in Power Query.
I wrote you some DAX (which is used in powerbi)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
100 | |
80 | |
63 | |
58 |
User | Count |
---|---|
148 | |
111 | |
94 | |
84 | |
67 |