Hi @marieke,
I’ve greated two queries, the first is a supporting query for which you can disable load.
This query is called LookUp
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xVvNUtxIEn6VWk6zEdNjlaTSz9FgjHfBhjBt74Rn56Cmi0ZutdSjH4M57TvsZV9hXmBPc/Ob7JNsVpZSqNQlujGD7QiDsKE+ZVXml19mJb/8sufz0An43o97bug7ngsPngcfqnS1ziQ8BL4vIvgs3CiGTxw/TPjEdbj657/ltbxhJ81lPZN1zd5ldZmws6yprtj//vVvdi6vSpY1N02ZfvlvJSv2olivZaa+V62z9+uP7Ru49AYKXER+/xVE4MfemzP1akLBR+YrnK5nWZJUsyQp2e21XM2SOftn4zhueHohk5y9lfJSf21C+gSpHqJAGJBxgHvh+qHF6HO5TsqkBnPe6qemrGTNLr/8UXZbIXMTzeujfZctFvQG6oEHTmAYHHKH4x7H7uYWHyRlxQq9z+0Wm2sHtDY+uJEYrh3i2tyLNhffT2afu4M7b3K1lUdZca1WukMICUE9eK5veIjrOVyoPfXiWFg8pKmvZZaxgyL/rZFlUbLjpqpkzvazpLk2LYkIRz143DcsCXzuO+geNhh9UIdq5TpNMnCOqmYTNr2Wci3LqijyCg7q4grOcbB9MYHi0Ys4NEAjEemj8dxR1JOiyReAV8isdf7D1TotJTsqC5lb3D90Wkw0iLuesaF+5AYOYvo+38T8e7NaT4pJJnPJqnWZ5oslbqiJQKyiV8AQvzMqDPENglGLDorVZVHWrafTvsF+1r39NAGJRHz1wJ3YMAmiDFcPoh0h5Y0KtKuiWOyGThHue4juGfEVRIGjcINxx7lK8vm6WK0BZJXO5zJblEVRs1UBjyYSMZf/vbgkJC7B8ODCj/vvcHIymT6LI0dMpuInF33IYvSJnIP/VLJk6rvYbbLMktXahCFa8YM/nbJCIhTN8CPOIgLMjfzP9xbiGT/a6i1W9N29hcgFD+lbR0VENCOc74FOjCA0BUV98DCKdVb2kak2kvw6yXPl+TUA6dx+mOa3wK8UPnv9BBV5JtTTyomI99EgTQ1JAKmB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6mZZmd1AGgvUTSPPNXtHaiAQFf3dQGAP4KhMP96qthGUMjPrYCCnwUDdddzh1xP6Dnj/rydwGtbj7a8+4AEM4glYNIwmJLv0VPYw574BCSHzZYq/7oSJVoeVCRb2wb5HOU9Tg525g2mYvqEjNcaYpfBzjSEoXKcLL91S5EbV6esSQOfmgVP8I60heheyTqCszJkziZkrVitzdcdYPXKMpO75DvakIpTEg+XPk0t5VgATeX7P5yDFJ2W7Xb/+Hw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [item_id = _t, order_id = _t, product_id = _t, product_type = _t, sku = _t, row_invoiced = _t, store_id = _t, created_at = _t, name = _t, qty_invoiced = _t]),
ReplaceNull = Table.ReplaceValue(Source,"null",null,Replacer.ReplaceValue,{"row_invoiced"}),
#"Changed Type" = Table.TransformColumnTypes(ReplaceNull,{{"item_id", Int64.Type}, {"order_id", Int64.Type}, {"product_id", Int64.Type}, {"store_id", Int64.Type}, {"row_invoiced", Currency.Type}, {"created_at", type date}, {"qty_invoiced", Int64.Type}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"order_id", "sku", "row_invoiced"}),
#"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each ([row_invoiced] <> null)),
#"Removed Duplicates" = Table.Buffer( Table.Distinct(#"Filtered Rows"))
in
#"Removed Duplicates"
.
For the second query I’ve written a custom function fxUpdatePrice and incorporated that into the code. You can copy both these queries into a new file, new blank query (make sure you rename the first query BEFORE you add the second)
let
fxUpdatePrice = (cPrice, cOrder, cSKU) => if cPrice = null then try Table.SelectRows( LookUp, (IT)=> IT[order_id] = cOrder and IT[sku] = cSKU ){0}[row_invoiced] otherwise cPrice else cPrice,
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xVvNUtxIEn6VWk6zEdNjlaTSz9FgjHfBhjBt74Rn56Cmi0ZutdSjH4M57TvsZV9hXmBPc/Ob7JNsVpZSqNQlujGD7QiDsKE+ZVXml19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ziZkrVitzdcdYPXKMpO75DvakIpTEg+XPk0t5VgATeX7P5yDFJ2W7Xb/+Hw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [item_id = _t, order_id = _t, product_id = _t, product_type = _t, sku = _t, row_invoiced = _t, store_id = _t, created_at = _t, name = _t, qty_invoiced = _t]),
ReplaceNull = Table.ReplaceValue(Source,"null",null,Replacer.ReplaceValue,{"row_invoiced"}),
ChType = Table.TransformColumnTypes(ReplaceNull,{{"item_id", Int64.Type}, {"order_id", Int64.Type}, {"product_id", Int64.Type}, {"store_id", Int64.Type}, {"row_invoiced", Currency.Type}, {"created_at", type date}, {"qty_invoiced", Int64.Type}}),
UpdatePrice = Table.RenameColumns( Table.RemoveColumns( Table.AddColumn(ChType, "Temp", each fxUpdatePrice([row_invoiced], [order_id], [sku]), type number ), "row_invoiced" ), {"Temp", "row_invoiced"})
in
UpdatePrice
.
I hope this is helpful.