1

I would like to add a table with some statistics in the print composer.

I want to show the rate of feature for a specific value. Let say I have a "Existing" field with 'Yes' or 'No' properties. I want to add a table with Y% Yes / X% No

I tried to use the expression dialog but with no success.

For info: I am on mac OSx and can't use SQL requests as there is an important but since 2 years with this.

  • What expression did you try? This should be simple enough to do, but we'll need to see what you've already attempted to see where it went wrong. – JoshC Mar 5 '18 at 12:59
1

Add a label to the print composer, and insert an expression using the aggregate function. enter image description here

For example, to calculate the percentage of "yes" values in the field "Existing" use this expression:

aggregate('mylayer','count', ' ',"Existing" = 'yes') / layer_property('mylayer','feature_count') *100

These label settings:

enter image description here

Give you a label that looks like this:

enter image description here

For other types of calculations, check out the other functions available in the expression editor.

  • Thank you that is a great answer ! Would it be possible to calculate percentage based on $lengh of each lines? And is it possible to have a 1 number precision? (Only one number after comma) – Arthur Mar 6 '18 at 8:25
  • 1
    Try the round() function for specifying 1 digit precision. – csk Mar 6 '18 at 17:05
  • The round () function is perfect for the digit precision. But I'am still facing difficulties with the calculation of % of length and not % of the number of lines. My layer is composed if road and I would like to know the proportion of the total length which have a specific value. – Arthur Mar 22 '18 at 14:32
  • I answered the question you posted, which was how to add "some statistics" to the print composer. Please accept this answer, and post a new question for any specific statistics that you want help calculating. – csk Mar 22 '18 at 16:13
  • Got it. I have accepted your answer and will post a new question. Thanks – Arthur Mar 22 '18 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.