# Calculating a single number fra an array in field calculator using other fields

For my final project, I would like to assess the earthquake risk of populated areas in California. For this I have two multipolygon layers containing data for Earthquakes, and populated areas respectively - named `Earthquakes` and `CA_pop`.

For each earthquake, a buffer zone describing its area of effect has been calculated. In the field calculator for the `CA_pop` layer, I am trying to calculate a risk, which is determined by the number of historical earthquakes hitting the populated area. For each earthquake, I would like to take its magnitude (a field in the Earthquake layer) and multiply it by the population density of the area, then sum all of this up.

So far I have managed to find the number of Earthquakes intersecting with each populated area, and from these get the magnitude of the earthquakes in an array by doing the following: `overlay_intersects(layer:='Earthquake', expression:=attribute("mag"))`

A preview of this could look like: Essentially, for this particular preview, I would like to do the following: `10^(6.7)*pop_dens + 10^(7.5)*pop_dens + 10^(7.93)*pop_dens + 10^(7.5)*pop_dens` to the power of, due to it being the Richter scale, and where the pop_dens is the population density of the given feature.

From here, I have however now been stuck for a while, and nothing I have tried seems to work. I feel like it is quite straight forward, but my inexperience in QGIS makes it a bit challenging.

You can try the following

``````with_variable(
'input_overlay_intersect',
overlay_intersects(layer:='Earthquake', expression:=attribute("mag")),
eval(
array_to_string(
array_foreach(@input_overlay_intersect, @element ^ "pop_dens"),
delimiter:='+'
)
)
)
``````

I've tested a standalone version before answering (so differences are `10` replaced by `"pop_dens"` and my array `array(6.7, 7.5, 7.93, 7.5)` by your provided input `overlay_intersects(layer:='Earthquake', expression:=attribute("mag"))`) e.g

``````with_variable(
'input_overlay_intersect',
array(6.7, 7.5, 7.93, 7.5),
eval(
array_to_string(
array_foreach(@input_overlay_intersect, @element ^ 10),
delimiter:='+'
)
)
)
``````