Hi,
I have 2 arrays:
local!years: {"2019", "2019", "2018", "2017"}
local!income: {1,2,3,4}
So the value in "income" is corresponding to its year in the "years".
and I want to get this data like : "year" - sum("income")
2019 - 3
2018 - 3
2017 - 4
And I am trying to loop
local!yearsUnion: union(local!years,local!years),
local!res: a!forEach(items:local!yearsUnion,expression: with(local!year: fv!item,local!impact,a!forEach(items: local!years,expression: with( local!val: 0,
if(local!year == fv!item,local!val = local!val + local!income[fv!index],local!val = local!val + 0))
)))
But I am not getting what I want. I can find how I can return the value from the nested loop, so to connect it with the value of the parent loop
Any suggestions?
Discussion posts and replies are publicly visible
The issue here is that you can't push any new values into a local variable from subsequent code like this (like in your a!forEach loop here). And for total clarification, the "=" operator always compares values, it doesn't change anything, and the "==" operator doesn't exist in Appian (I know you may have just written it that way as an example though, but I don't want others seeing this to potentially get confused).
The solution already posted by arunkumarc should work - basically what's happening there is, you create a new list of just the unique years, then iterate over each one of those, and for any given (unique) year, you check the original Years and Income arrays, and sum any members of the Income array at positions matching the current year in the Years array.