I have a dataset, a polygon, with several columns, let's say:
Site | Species1 | Species2 | Species3 |
---|---|---|---|
1 | 85 | 23 | 90 |
2 | 73 | 20 | 0 |
3 | 0 | 0 | 0 |
4 | 0 | 0 | 70 |
5 | 0 | 75 | 60 |
I have different sites and data about several species, each is a % of the surface covered by that species. I wrote three sample columns with data about species but it is actually hundreds.
What I need is an if
function that creates a 4th column adding the total amount of species present in each site, assuming that if Speciesn=0
the species is absent and Speciesn>0
the species is present. For each column I need something like:
CASE
WHEN "Species1" > 0 THEN 1
ELSE 0
END
But I definitely need a loop to iterate through columns!
So the resulting column should look like this:
Site | Species1 | Species2 | Species3 | Total |
---|---|---|---|---|
1 | 85 | 23 | 90 | 3 |
2 | 73 | 20 | 0 | 2 |
3 | 0 | 0 | 0 | 0 |
4 | 0 | 0 | 70 | 1 |
5 | 0 | 75 | 60 | 2 |