0

I am trying to calculate a percentage based on two fields in my table. I am using views and I have a table which has 2 fields, one field is an aggregation of of all records and the other is an embedded view which has another number - I used the Views Field View module for embedding the field.

How can i get a percentage between these 2 fields. The Math Expression field is not supported in drupal 8 and I have also tried the views_simple_math_field and it didn't help me at all. Please help!

0

i tried in output code:

<?php 
echo count($row->field_a) + count($row->field_a) ;
?>

and the result is:
enter image description here

I modified the view, and used aggregation.

enter image description here

I modified the field a:

enter image description here

I modified the field b:

enter image description here

I modified the field php:

enter image description here

And the code:

enter image description here

And result:

enter image description here

-1

if you want sum two field, you install the module: https://www.drupal.org/project/views_php

As an example, add two fields in your content "basic pages":

  1. field_a
  2. field_b

enter image description here I create a content of example: nid = 43

enter image description here

Please create a new view as is the image. enter image description here

in your field "Global: PHP (php)" in the section: "Output code".

sum two fields please use the following code

<?php 
echo $row->field_a +$row->field_a ;
?>

enter image description here

preview

enter image description here

1
  • Thamk you very much for your response, But my fields are aggregated as COUNT so its not working – tendaitakas Nov 10 '17 at 6:37

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.