Jump to content
  • 0

How to apply custom formula for sub-groups in aggregation


ttanemori

Question

I have a DataPage that shows Total and Due by Group.

I used two aggregations, one is SUM for total and another one is SUM-2100 for due.

Those values are fine in Group, but Caspio tries to calculate from entire values.

I assume that "-900" is coming from 2100-(400+800). What is the best way to show "-3000" in TOATAL DUE?

(COUNT([@field:Applicants_Email])*2100-SUM) did not work because COUNT increase a number by one.

I am fine to hide "TOTAL DUE" if there is no good way. But, I cannot find a way to hide it. Any idea?

 

Thank you very much.

 

 

 

caspio_fw.png.39288c378087f006e7fa13c462d48158.png

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hello @ttanemori,

Since the formula in the Aggregations has the same logic for Totals and groups, please try this JavaScript code.

This code replaces the value in the Total Due with the sum of values that you receive in the groups (in your example it summarizes -1700 and -1300).

 

<script type="text/javascript">

document.addEventListener('DataPageReady', sumGroups);

function sumGroups() {
 const totals = [];
 document.querySelectorAll("td[class*='cbResultSetGroup1LabelCellNumberDate']").forEach(elem => {
 totals.push(elem.innerText);
});

 const result = totals.reduce( (accumulator, currentValue) => parseFloat(accumulator) + parseFloat(currentValue) );

 document.querySelector('tr[data-cb-aggregation="Aggregate1"] > .cbResultSetTotalsData').innerText = result;
 document.removeEventListener('DataPageReady', sumGroups);
};

</script>

Replace Aggregate1 with the Aggregate2, etc. depending on the number of your Aggregate field.

Add this code to the Header section on the "Configure Results Page Fields" screen of your DataPage.

Do not forget to disable HTML editor before pasting the code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...