I have a four column table. The third and fourth columns are in whole number
format.

I need to create a formula, that I can repeat in all cells of the fourth
column that, depending on the value of the test of the cell in the first
column of any row (not empty, empty) will:

If not empty: just copy the value of the third cell of the same row as the
tested cell into the fourth row.

If empty: fill the cell in the fourth column and same row of the tested cell
with the results of a selective sum. That is, add up the values of those
cells in the third column from the row inmediately bellow, for which the cell
in the corresponding row in the first column (that is not empty), meets
certain criteria.