In the doc attached you find the issue
TLTR : I have two lists and I need to multiply them (1,0,1,0,0,1) * (1,3,5,7,11,13)
and I do not know how. For Sum()
there is substantial input on this matter, but for Product()
I could find nothing to help me to solve this puzzle.
and feedback welcome!
best and thanks christiaan
Hey @Christiaan_Huizer,
Strictly speaking, it’s not “multiplication” (because that would make an N x N matrix) but more of “masking”.
The logic here is to multiply Nth element of the first list by the Nth element of the second list. Which means you still have to iterate (i.e. perform the same operation once per list item) but instead of iterating on items themselves you should iterate on indices 1, 2, 3 ... List.Count()
so that you can use the same index on both list to extract corresponding values:
Sequence(1, thisRow.transformed.Count()).FormulaMap(
thisRow.transformed.Nth(CurrentValue) * thisRow.[days per response].Nth(CurrentValue)
)
Here I’m making another list that’s a sequence of numbers from 1 to transformed.Count()
and then I’m using items in this list (numbers from 1 to last) to get .Nth()
element of each list and multiply them to produce Nth element of a resulting list.
I implemented this in your doc. Btw, no need to use ListCombine()
there — simply use List()
to create a list of elements that you enumerate as function parameters. Also no need to ListCombine()
on a column — you can simply reference that column (see Input 2 / Days per response column)
6 Likes
goodmorning @Paul_Danyliuk and many thanks for both providing the solution and some background information. I assumed that ListCombine was the way to go instead of List(), so thanks for simplifying the logic.
The learning I take away from this exercise is that you only apply on one column (or list) the index logic via Sequence () and Count() and not on both when you explain very clearly:.
Which means you still have to iterate (i.e. perform the same operation once per list item) but instead of iterating on items themselves you should iterate on indices 1, 2, 3 ... List.Count()
so that you can use the same index on both list to extract corresponding values:
Thanks a lot again, this is not only a wonderful solution for this specific problem, it also opens the door to find solutions for alike problems, like pulling in data from an other table via this index logic to find for example - which are the top three items that require most days.
Enjoy your Sunday!
Cheers, Christiaan
That could be solved simpler with a Slice() function that extracts items from a list by given start index and optional end index:
SomeTable.Sort(column: [Total Days], ascending: false).Slice(1, 3)
Cheers!
Thanks for the suggestion @Paul_Danyliuk . In terms of numbers this is indeed the easiest way to go. But then reality checks in and the next question is o yeah what permit is related to the nr 3, 2 and 1. And off we go.
What I tried to do was to apply the proposed logic in a different table to inject the outcome of the masking on each row in that new table. This is easy enough when you apply addRow via a button. Every new row receives the value valid for thisRow (in my example Row 1 - Row 7).
Next I tried to use ModifyRows to obtain the same result in an already exsiting table. I thought that using the Nth() value of this list on the Nth() row should be the solution, but I did not succeed.
I looked at it for hours, I went our to play basketball to empty my head, but I do not see the issue when I came back.
Thanks in advance!
I solved th puzzle in two steps:
I applied AddOrModifyRows to fill out the second table with the data per column and second I splited the lists living in one row via a formula over the existing rows related to this applicant. For the sake of clarity I kept the columns visible that contain the respective steps.
Feel free to have a look:
Best, Christiaan
1 Like