Forum Discussion
Anonymous
6 years agoNot applicable
Update Historical Table with Daily Data in Power Query
I start this exercice having two tables with the same Columns (ID, Offer, Price & Total Views). One of them acts as my Historical data, the second one is a daily update that I use to feed the first o...
- 6 years ago
Hi Anonymous ,
You could refer to below M code yo see whether it work or not.
let Source = Table.NestedJoin(history, {"id"}, daily, {"id"}, "daily", JoinKind.LeftOuter), #"Expanded daily" = Table.ExpandTableColumn(Source, "daily", {"price", "view"}, {"daily.price", "daily.view"}), Custom1 = Table.ReplaceValue(#"Expanded daily",each [price], each if [price]=[daily.price] or [daily.price]=null then [price] else [daily.price], Replacer.ReplaceValue, {"price"}), Custom2 = Table.ReplaceValue(#"Custom1",each [view], each if [view]=[daily.view] or [daily.view]=null then [view] else [daily.view], Replacer.ReplaceValue, {"view"}), Custom3 = Table.ReplaceValue(#"Expanded daily",each [daily.view], each if [view]=[daily.view] and [price]=[daily.price] or [daily.view]=null then null else DateTime.LocalNow(), Replacer.ReplaceValue, {"daily.view"}), #"Removed Columns" = Table.RemoveColumns(Custom3,{"daily.price"}) in #"Removed Columns"In addition, if the date column in daily table, you could change code like below(you also need to exapnd this column in table)
Custom3 = Table.ReplaceValue(#"Expanded daily",each [daily.view], each if [view]=[daily.view] and [price]=[daily.price] or [daily.view]=null then null else [daily.date], Replacer.ReplaceValue, {"daily.view"})Best Regards,
Zoe ZhiIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
dax
6 years agoCommunity Support
Hi Anonymous ,
You could refer to below M code yo see whether it work or not.
let
Source = Table.NestedJoin(history, {"id"}, daily, {"id"}, "daily", JoinKind.LeftOuter),
#"Expanded daily" = Table.ExpandTableColumn(Source, "daily", {"price", "view"}, {"daily.price", "daily.view"}),
Custom1 = Table.ReplaceValue(#"Expanded daily",each [price], each if [price]=[daily.price] or [daily.price]=null then [price] else [daily.price], Replacer.ReplaceValue, {"price"}),
Custom2 = Table.ReplaceValue(#"Custom1",each [view], each if [view]=[daily.view] or [daily.view]=null then [view] else [daily.view], Replacer.ReplaceValue, {"view"}),
Custom3 = Table.ReplaceValue(#"Expanded daily",each [daily.view], each if [view]=[daily.view] and [price]=[daily.price] or [daily.view]=null then null else DateTime.LocalNow(), Replacer.ReplaceValue, {"daily.view"}),
#"Removed Columns" = Table.RemoveColumns(Custom3,{"daily.price"})
in
#"Removed Columns"
In addition, if the date column in daily table, you could change code like below(you also need to exapnd this column in table)
Custom3 = Table.ReplaceValue(#"Expanded daily",each [daily.view], each if [view]=[daily.view] and [price]=[daily.price] or [daily.view]=null then null else [daily.date], Replacer.ReplaceValue, {"daily.view"})
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous6 years agoNot applicable
Wow! It hepls me to sort my code out! Thanks a lot Zoe.