Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using Sum in CQL

Craig_Harley
Contributor
April 8, 2025

hi, i'm trying to sum a column, whose values are alphanumeric

i.e. can have 0, 1 12, 100, n/a and TBC, how do i exclude the character fields so i can sum the numbers?

2 answers

1 vote
Aliaksei Mikhailau _Stiltsoft_
Contributor
April 9, 2025

Hello @Craig_Harley ,

As you mentioned the Table Transformer macro of our Table Filter, Charts & Spreadsheets app, let me propose the following type of solution:

SELECT
SUM(T1.'Your column name'::number) AS 'Numeric Sum'
FROM T1
WHERE MATCH_REGEXP(T1.'Your column name', "^[0-9]+(.[0-9]+)?$")

Craig_Harley
Contributor
April 15, 2025

hi Alexey, this works perfectly on the first of 4 columns I am trying to Sum using this approach, however when i apply to the 2nd column, it does not give the correct result. I am additionally rounding to 2 decimal places

the SQL i am using is

SELECT
'Sum Transaction Totals',
ROUND (SUM (T1.'Transactions1'::number), 2) AS 'Peak Load (TPS)',
ROUND (SUM(T1.'Transactions2'::number), 2) AS 'Peak Load (TPM)'
FROM T1
WHERE MATCH_REGEXP(T1.'Transactions1', "^[0-9]+(.[0-9]+)?$")
AND MATCH_REGEXP(T1.'Transactions2', "^[0-9]+(.[0-9]+)?$")

any thoughts?

Like • Marc - Devoteam likes this
Aliaksei Mikhailau _Stiltsoft_
Contributor
April 18, 2025

Hello @Craig_Harley ,

The initially proposed approach is for the only column. This approach doesn't work correctly for multiple columns because it filters entire rows. If one column has a non-numeric value, the whole row is excluded, even if the other column has valid data. As a result, valid values are skipped, and the totals are incorrect.

Using CASE WHEN MATCH_REGEXP(...) THEN ... ELSE 0 inside each SUM should allow independent filtering per column, ensuring accurate aggregation. Please try this SQL query:

SELECT

'Sum Transaction Totals',

ROUND(SUM(
CASE
WHEN MATCH_REGEXP('Transactions1' + "", "^[0-9]+(\.[0-9]+)?$")
THEN CAST('Transactions1' AS number)
ELSE 0
END
), 2) AS 'Peak Load (TPS)',

ROUND(SUM(
CASE
WHEN MATCH_REGEXP('Transactions2' + "", "^[0-9]+(\.[0-9]+)?$")
THEN CAST('Transactions2' AS number)
ELSE 0
END
), 2) AS 'Peak Load (TPM)'

FROM T1

1 vote
Marc - Devoteam
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 8, 2025

Hi @Craig_Harley 

How would you see this, CQL is for text searching.

I can't see the sum option in using CQL

Craig_Harley
Contributor
April 8, 2025

let me re-phrase, I am using SQL in table Transformer from Table Filter and charts

Marc - Devoteam
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2025 edited

Hi 

To sumup, see this doc.

I don't think there are options to exclude.

https://docs.stiltsoft.com/tfac/cloud/calculations-in-tables-42239860.html 

You could raise this as the app developer's support portal.

Like • 2 people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
ENTERPRISE
TAGS
atlassian, confluence administration, confluence admin training, confluence learning path, manage users and permissions, confluence certification, atlassian learning, cloud admin tools, streamline collaboration, confluence admin best practices

New Confluence Admin Learning Path! 🤩

Confidently manage users, permissions, and content in Confluence. This self-paced learning path helps admins streamline collaboration, improve user experience, and apply the best practices to get the most out of Confluence in any cloud environment.

Start Learning Now
AUG Leaders

Atlassian Community Events