# How to calculate percentages using QGIS field calculator expression? I am new to QGIS. I am wanting to calculate a field using other fields and some operators. Here is my expression:

``````case
When "RVM_CAT" =  'B' OR "RVM_CAT" = 'C' Then ("PC1" /100) * "RE_ha"
When "RVM_CAT" = 'R' Then ("PC1_1" /100) *  "RE_ha"
When "RVM_CAT" = 'X' AND "FPC2011"  = 'gr12' Then ("PC1_1" /100) *  "RE_ha"
ELSE 0
end
``````

When it runs, it looks like its only calculating values when the PC1_1 value or the PC1 value is 100. If I take out the Else 0, its the same thing.
There are over 370,000 features
The PC fields are percentages that i need to use to calculate the percentage of area from the M column. The RVM_CAT column tells me if I use PC1 or PC1_1. So the answer for row 2 uses PC1_1 and is (50/100)*32.03. WHile the answer for row 3 uses PC1 and is 100/100)*254.73

• Hi, it would be good if you could add samples of what is expected. Just a short table of which values you throw in, what datatype they are, what you expect to happen and what actually happens instead. – Matthias Kuhn Aug 20 '14 at 7:13
• I'm might be wrong but aren't the second and third "WHEN" statement's results exactly the same? What are the other possible values for PC1 and/or PC1_1? – Alexandre Neto Aug 20 '14 at 8:32
• And don't forget to use the IN Operator. «"RVM_CAT" = 'B' OR "RVM_CAT" = 'C'» is the same as «"RVM_CAT" IN ('B','C')». – Alexandre Neto Aug 20 '14 at 8:37
• Sounds like you're doing integer division, if it only gives you nonzero values for an input of 100. Try instead to divide by 100.0 or do the multiplication first if you don't care about the decimals. – lynxlynxlynx Aug 20 '14 at 9:57
• I added columns of the table to assist. – RFwisher Aug 21 '14 at 23:49