Forum Discussion
Reconciliation
First step: find all allowed combinations on either side. Here's the sample code for the Bank table (five items). For later reference to the values an index column is added as a convenience (not strictly required)
Bank table
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjJU0lEyNNM3MNU3MjAyAXEMlGJ1gBJGQLaRCZKECVTCGCRhgSRhBpUAsY0NsUiYgnTrG5jBrTBRio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Value", Currency.Type}, {"Date", type date}},"en-GB"),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type)
in
#"Added Index"
Combine function to find and deduplicate combinations
(tablea,listb)=>
let
Next = Table.AddColumn(tablea,"id",each listb),
#"Expanded id" = Table.ExpandListColumn(Next, "id"),
#"Replaced Value1" = Table.ReplaceValue(#"Expanded id",each [ID],each List.Sort(List.Distinct([ID] & {[id]})),Replacer.ReplaceValue,{"ID"})
in
Table.Distinct(Table.SelectColumns(#"Replaced Value1",{"ID"}))
Final result for combinations of five items based on the Bank table
let
Source = List.Accumulate({1..Table.RowCount(Bank)-1},Table.FromList(List.Split(Bank[Index],1), Splitter.SplitByNothing(), {"ID"}),(state,current)=>Combine(state,Bank[Index])),
#"Extracted Values" = Table.TransformColumns(Source, {"ID", each Text.Combine(List.Transform(_, Text.From), ","), type text})
in
#"Extracted Values"
Then you can lookup the sum value for all these combinations, repeat the process for the seven items of the Financials table, and the do yet another cartesian to match the sums.
Thank you for the solution.
It does work (of course we need another column equal to the total values of the combination), but for the case facing many rows, it is too time-consuming.
Imaging the case of 100 rows (which is not too much) in the bank table, the combinations are too much.
Do you think it is possible to increase the efficency in another way?
- lbendlin1 year agoSuper User
While you cannot cheat combinatorics, the results are immutable. I only computed them as a finger exercise. For better performance you want to have them precomputed. The actual value aggregation and comparison does not grow as exponential as it is less and less likey that values match. Not sure if it is linear (only real world data can tell) but definitely not exponential.
In real life the statement timing constraints will play a much larger role.