Forum Discussion
Omid_Motamedise
1 year agoSuper User
Reconciliation
Hi, I post every other day a challenge on my LinkedIn page, and this week challenge number 110 (provided in the below link) was one of the hard ones, I am eager about other possible solutions: https...
dufoq3
1 year agoCommunity Champion
Hi, I've played with this a while and I can provide possible combinations of Finacial Transactions for each Bank Transactions (I know that assignment was different)
Output
let
BankTransactions = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjJU0lEyNFCK1QGyjYBsEyjbGMg2g7JNkNimIPUmSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Value = _t]),
FinancialTransactions = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjNU0lEyNFCK1QGyjYBsYyjbGMg2hTBNEExTJNVmILYRlGMO5JgoxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Value = _t]),
BTChangedType = Table.TransformColumnTypes(BankTransactions,{{"Value", type number}}),
FTChangedType = Table.TransformColumnTypes(FinancialTransactions,{{"Value", type number}}),
FTBufferedIDList = List.Buffer(FTChangedType[ID]),
Ad_FTCombinations = Table.AddColumn(FTChangedType, "Combinations", each
[ a = List.PositionOf(FTBufferedIDList, [ID]),
b = List.Buffer(List.RemoveRange(FTBufferedIDList, 0, a+1)), //list for current row combinations
c = List.Count(b),
d = List.Accumulate({1..c}, {[ID]}, (state, current)=> state &
List.Transform({0..c-1}, (y)=>
[ d1 = List.Range(b, y, current),
d2 = if List.Count(d1) < current then null else Text.Combine({[ID]} & d1, "+")
][d2]) ),
e = if b = {} then {[ID]} else List.RemoveNulls(d)
][e], type list),
AllCombinations = Table.FromList(List.Combine(Ad_FTCombinations[Combinations]), (x)=> {x}, type table[ID=text]),
Ad_Value = Table.AddColumn(AllCombinations, "Value", each
[ a = Text.Split([ID], "+"),
b = List.Transform(a, (x)=> List.First(Table.SelectRows(FTChangedType, (y)=> y[ID] = x)[Value])),
c = List.Sum(b)
][c], type text),
Filtered = Table.SelectRows(Ad_Value, each [Value] <= List.Max(BTChangedType[Value])),
BufferedCombinations = Table.Buffer(Filtered),
StepBackToBankTransactions = BTChangedType,
Ad_Combinations = Table.AddColumn(StepBackToBankTransactions, "Combinations", each BufferedCombinations, type table),
AddedCustom = Table.AddColumn(Ad_Combinations, "Custom", each Table.SelectRows([Combinations], (x)=> x[Value] = [Value])),
ExpandedCustom = Table.ExpandTableColumn(AddedCustom, "Custom", {"ID"}, {"Possible Combinations"}),
RemovedColumns = Table.RemoveColumns(ExpandedCustom,{"Combinations"})
in
RemovedColumns