
Announcements
Hi,
I want to calculate a checksum of a number based on a weighting.
To let it keep simple, I have a number varNumber 123456.
The weighting is varWeigthing 131313.
I want to multiply the first position of varNumber with the first position of varWeigthing and so on and get the sum as a result.
In this example:
1 * 1 = 1
2 * 3 = 6
3 * 1 = 3
4 * 3 = 12
5 * 1 = 5
6 * 3 = 18
1+6+3+12+5+18 = 45
So I want to get the result 45.
Any idea?
Thanks
Stefan
Hi @stefansc,
With the assumption that both numbers will be of equal length / have the same amount of characters, you could use the code below. I have added inline comments to further explain the functionality.
Set(
gblTotal,
//Sum the returned array of products
Sum(
ForAll(
//Loop through the amount of characters
//Sequence generates an array of sequential numbers up to the amount defined
Sequence(Len(varNumber)),
//Fetch the number at the current loop's index for both variables & multiply
Index(
Split(
varNumber,
""
),
Value
).Value * Index(
Split(
varWeigthing,
""
),
Value
).Value
),
Value
)
)
If this solves your question, would you be so kind as to accept it as a solution. ✔️
If you liked my solution, please give it a thumbs up. 👍