Confluence - Table Transformer Macro - Need help in adding rows based on common value

Karthika_Natarajan
Contributor
June 6, 2023

Hi, 

I have a table like this. 

I want to group the Items and calculate the total price for the total quantity. 

Items    Price   quantity

item 1     3         10

item 1     3           6

item 2     5           5

item 2     5         10

 

I want the Result table like this.  I tried to sum it using Group By but it doesn't help. Kindly help me with the query.

Items     Price     quantity    Total Price

Item1       3            16             48

Item2       5            15             75

1 answer

1 accepted

3 votes
Answer accepted
Stiltsoft support
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.
June 6, 2023

Hi @Karthika_Natarajan ,

Please try the following SQL query:

Tue 7-1.png

SELECT 'Items', 'Price', 'Total Quantity',
('Price' * 'Total Quantity') AS 'Total Price'
FROM
(SELECT *,
SUM('Quantity') AS 'Total Quantity'
FROM T*
GROUP BY 'Items', 'Price')

Tue 7-2.png

Hope this helps your case.

Karthika_Natarajan
Contributor
June 6, 2023

Yeah, this works fine. Thanks

Like Stiltsoft support likes this
Stiltsoft support
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.
June 7, 2023

Hi @Karthika_Natarajan ,

You may also the this query that looks more neat:

SELECT 'Items', 'Price',
SUM('Quantity') AS 'Total Quantity',
SUM('Quantity' * 'Price') as 'Total Price'
FROM T* GROUP BY 'Items', 'Price'

The result will be the same.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events