How to convert string count into number? I have string count column in views i.e. by using the view aggregating I am counting the nodes of content, along with this I have field_number column i.e. from content type.

Now I want to subtracts these two column, while using math-expression its taking the string count column as string its not considering the count number.

Is there any solution to subtract these two fields?


2 Answers 2


Drupal doesn't provide any conversion of value in "Math Expression" field. So we need to fix it in another way, for example following these steps:

  • Add two new columns "string count" and "field_number" same as previously added, excluding
    • When add fields tick "Exclude from display" checkbox
    • Select "Plain Text" to "Formatter" dropdown
  • After it, edit "Math-Expression" field, in "Expression" textarea write your mathematical expression with that newly added fields, e.g. [string_count_1] - [field_number_1]
  • do we need to add one more time both the column in view?
    – neethu
    Nov 18, 2015 at 7:43
  • If you want display only plain text of that two columns, without any formating/HTML tags(i.e. <p>), then you can directly edit both columns and Select "Plain Text" to "Formatter" dropdown of both columns. Else we need to add one more time both the column in view
    – PHP Team
    Nov 18, 2015 at 8:18
  • please check the scrren shot there is no formatter dropdown for tittle count column
    – neethu
    Nov 18, 2015 at 9:01
  • Is there link on "Title" field required? If not then remove check on "Link this field to the original piece of content" check-box. Else you must add new same column and make it "Exclude from display".
    – PHP Team
    Nov 18, 2015 at 9:27
  • let me check so over all u mean to say for 1]field_max_room_capacity need to choose text from formator drop down 2] and for title need to uncheck link this field to the original piece of content then need 3] need to add math expression following to field token right?
    – neethu
    Nov 18, 2015 at 9:45

Use Views PHP

This module allows the admin account (user 1) to add fields, filters and sorts to views which use PHP code. It also supports additional accounts when the core PHP Filter module is enabled

Then add PHP field in Global category and do that with php

in OUTPUT of field write something like(it is example and you should write it according your field)

//first dpm($data) and dpm($row) to see what data exists there then 
echo intval($data->field_a['raw'][0]['value']) + $data->field_b['raw'][0]['value'];
  • I added something like this <?php echo intval($data->title_1['raw'][0]['value']) + $data->field_max_room_capacity['raw'][0]['value']; ?> but its retaining zero value in column
    – neethu
    Nov 18, 2015 at 8:07
  • @neethu did you try dpm($data) before it to see what you have? and also please provide dpm($data->title_1['raw'][0]['value']); result for me.tnx
    – Yuseferi
    Nov 18, 2015 at 8:11
  • thanks, well is it something over all <?php dpm($data->title_1['raw'][0]['value']); echo intval($data->title_1['raw'][0]['value']) + $data->field_max_room_capacity['raw'][0]['value']; ?> Sorry if i am wrong
    – neethu
    Nov 18, 2015 at 8:51
  • @neethu I want see the exist data to help you more, final solution is something like <?php echo intval($data->title_1['raw'][0]['value']) + $data->field_max_room_capacity['raw'][0]['value']; ?>
    – Yuseferi
    Nov 18, 2015 at 8:59
  • please find the screen shot u may find what mistake i am doing
    – neethu
    Nov 18, 2015 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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