1

How do I show the percentage value in a views_field?

  • col(1) (group by) field_a
  • col(2) (count)field_a *100/number of results " -->@total"

I'm still not able to use @total in a computed_field or a math-expression_field or a global_custom_field.

I need this value for the Highcharts module, so using "aggregation plus" also seems not the solution.

Using a PHP field inside views is highly risky for security reasons as I read here in other answers.

0

to achieve some calculations I see 2 different solutions.

1/ You create a custom sql query with (db_query) inside a custom module that gonna trigger a view to render, your select clause will make the calculation for you so you will have your result that you are going to display inside a custom field in your view. You can see the actual query you are executing by using the devel module and then tweak it.

2/ You can use computed_field module but it's a really dangerous thing to integrate PHP inside a field somewhere, because if your php breaks, you will break your complete site, and need to rollback your database. But I don't suggest this solution because it's really risky for your site.

I hope it helps

Cheers

| improve this answer | |
  • ty denis, additional info: the view i'm talking about, is part of a series from global view areas (all highcharts) with inherit contextual date filters. Do you still think, i can reach this with your suggestion 1/? The value i need is yet there, but on the wrong place as i can display it in "global:result summary @total". So suggestion /1 is a redundant query, isn't it? My idea is to bring this existing @total to sthg like a custom token - have you an additional idea? sry for my english – user2699953 Jul 25 '16 at 6:09
  • Hi. I'm not sure to understand well, but if the value is already in the view, try to display all the fields you have access to,but you won't be able to do a calculation on it. Then add a custom field at the end of your list of fields, and by using "rewrite the output" you might find what you want about replacement tokens. – Denis Kolmerschlag Jul 25 '16 at 6:39
  • what i mean is: by adding a global:result summery for example in the views header - there is a token called "@ total" showing total numbers of rows in the view. But in dont get access to this token, in the replacement patterns or "rewrite the output- replacements" of any field. With this @total i would be able to do all the following stuff i need. Hope this was understandable ;) – user2699953 Jul 25 '16 at 6:57
  • Having some information in the view header doesn't mean having information in the resultset. – Denis Kolmerschlag Jul 25 '16 at 23:04

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.