Forum Discussion
wsindharta
2 years agoHelper I
Loop Function
Hi, i need help, i have one table and need loop function. below is the table, basically after i select the desired order no, i will get "To Part No", "To Container" "To Qty", "From Part No", ...
- 2 years ago
sample data and assignment:
Result:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdJLDsMgDATQu7BOJP8xZ4ly/2sUQtSaulK6AwY9RhbHUdyAsaFS2QoqoleC6n0TA7Z3WgF4puRKxjsCUCvn9i+FkZKbqqDSBtXjm5r807tb6QFAvEbf5qfeONOlgKYCFEwTb32NdRTvRyROwvtIbTEpmpZM/mF6NOtlejRF4WlSGbWI0oXqUnQZaE2m/DBbMBkvcxmotKfpZ1Njz2nK0lOi6amnZpMgmDTN/pnOFw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Order No." = _t, #"To Part No" = _t, #"To Container" = _t, #"To Qty" = _t, #"From Part No" = _t, #"From Container" = _t]), Result = [ //remove spaces and dots from column names end + added Index column data = Table.Buffer(Table.AddIndexColumn(Table.TransformColumnNames(Source, each Text.Trim(_, {" ", "."})) , "Index", 0, 1, Int64.Type)), lg = List.Generate( ()=> [ x = 0, idx = 0, merge = Table.NestedJoin(Table.FromRecords({data{x}}), {"From Part No", "From Container"}, data, {"To Part No", "To Container"}, "Merge", JoinKind.LeftOuter), original = [ Original Order No = data{idx}[Order No], Original To Part No = data{idx}[To Part No], Original To Container = data{idx}[To Container] ], output1 = [Level = 1] & original & data{0}, output2 = output1 ], each [ idx ] <= List.Max(data[Index]), each [ x = [x]+1, idx = if output1 = [output1] then [idx]+1 else [idx], merge = Table.NestedJoin(Table.FromRecords({[output2]}), {"From Part No", "From Container"}, data, {"To Part No", "To Container"}, "Merge", JoinKind.LeftOuter), original = if Table.IsEmpty(merge{0}[Merge]) then [ Original Order No = data{idx}[Order No], Original To Part No = data{idx}[To Part No], Original To Container = data{idx}[To Container] ] else [original], output1 = if Table.IsEmpty(merge{0}[Merge]) then [Level = 1] & [output1] else [Level = [output2][Level]+1] & merge{0}[Merge]{0}, output2 = if output1 = [output1] then [Level = 1] & original & data{idx} else original & output1 ], each [output2] ), toTable = Table.RemoveColumns(Table.FromRecords(lg), {"Index"}, MissingField.Ignore) ][toTable] in Result
wsindharta
2 years agoHelper I
hi dufoq3
thanks. sorry but one more thing is it possible to do this transformation in DAX ? i just realized how long it takes when i try to applied to actual data set. data set it self has 1.2Million row, and so far it already took 1 hour and only finish load 123 rows.
what i have in mind, if we do it in DAX, the user will input Part No. and it will only loop that particular Order and Part No.
is it possible ?
dufoq3
2 years agoCommunity Champion
Sorry wsindharta, but I'm not that skilled in Dax.
- wsindharta2 years agoHelper I
Hi dufoq3
thanks, let me ask other who view this thread, hopefully someone can help with DAX.
Hi anyone can help me to create similar solution in dax ?
thanks
regards,
Sind