sandy666
03-07-2021, 11:03 PM
(question from the web (https://www.mrexcel.com/board/threads/use-table-to-edit-values-of-another-table-in-power-query.1164083/#post-5652183))
How do we update values in Table A using the Values of Table B and keep the rest as they are?
TABLE ATABLE BResult
SiteIddateValue 1Value 2Value 3SiteIddateValue2SiteIddateValue 1Value 2Value 3
1
01/01/2020
5
20
500
1
01/01/2020
25
1
01/01/2020
5
25
500
1
02/05/2020
6
60
100
3
01/01/2021
73
1
02/05/2020
6
60
100
3
01/01/2021
2
85
250
3
01/01/2021
2
73
250
5
01/01/2020
6
14
566
5
01/01/2020
6
14
566
let
SourceA = Excel.CurrentWorkbook(){[Name="TableA"]}[Content],
SourceB = Excel.CurrentWorkbook(){[Name="TableB"]}[Content],
Join = Table.NestedJoin(SourceA, {"SiteId", "date"}, SourceB,{"SiteId", "date"}, "Table", JoinKind.LeftOuter),
Expand = Table.ExpandTableColumn(Join, "Table", {"Value2"}, {"Value2"}),
IF = Table.AddColumn(Expand, "Custom", each if [Value2] = null then [Value 2] else [Value2]),
TSC = Table.SelectColumns(IF,{"SiteId", "date", "Value 1", "Custom", "Value 3"}),
Ren = Table.RenameColumns(TSC,{{"Custom", "Value 2"}}),
Type = Table.TransformColumnTypes(Ren,{{"date", type date}})
in
Type
How do we update values in Table A using the Values of Table B and keep the rest as they are?
TABLE ATABLE BResult
SiteIddateValue 1Value 2Value 3SiteIddateValue2SiteIddateValue 1Value 2Value 3
1
01/01/2020
5
20
500
1
01/01/2020
25
1
01/01/2020
5
25
500
1
02/05/2020
6
60
100
3
01/01/2021
73
1
02/05/2020
6
60
100
3
01/01/2021
2
85
250
3
01/01/2021
2
73
250
5
01/01/2020
6
14
566
5
01/01/2020
6
14
566
let
SourceA = Excel.CurrentWorkbook(){[Name="TableA"]}[Content],
SourceB = Excel.CurrentWorkbook(){[Name="TableB"]}[Content],
Join = Table.NestedJoin(SourceA, {"SiteId", "date"}, SourceB,{"SiteId", "date"}, "Table", JoinKind.LeftOuter),
Expand = Table.ExpandTableColumn(Join, "Table", {"Value2"}, {"Value2"}),
IF = Table.AddColumn(Expand, "Custom", each if [Value2] = null then [Value 2] else [Value2]),
TSC = Table.SelectColumns(IF,{"SiteId", "date", "Value 1", "Custom", "Value 3"}),
Ren = Table.RenameColumns(TSC,{{"Custom", "Value 2"}}),
Type = Table.TransformColumnTypes(Ren,{{"date", type date}})
in
Type