How to use viewfield to make calculations in another field?

Created on 8 June 2024, 8 months ago

Problem/Motivation

I created a first viewfield1. It contains an aggregation of multiple nodes. But returns one number. e.g. 5, 000, 001.00 which is a strange output (with the blanks) anyway.

I created a second viewfield2. Also containing an aggregation, returning a single sum value.

So now I want to make a calculation with these two fields to create a new view that shows that result.

In the new view I would like to create a field (e.g. global textfield) to do viewfield2/viewfield1.

But the global text field does not work. No calculation is taking place.

I tried
a) Simple Math Field
which results to 0. Which is wrong.

b) Twig in Views
{% set mysum= field_my_sum|int %}
{% set someth= field_my_something|int%}
{% set proz= mysum/someth%}
{{ proz }}

Which causes errors on the site. Besides there is only int not double or decimal.

c) Could not find tokens to address the raw value of the viewfield1 and viewfield2.

All in all, all the working methods for number fields don't seem to work with viewfield.
Could someone please indicate a proper strategy how to make calculations with results from the viewfields?
Thank you very much.

If we gather a couple of examples here, I will gladly write that up for the documentation.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Component

Documentation

Created by

🇦🇹Austria maxilein

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024