Forums

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

Joining the total SUM of two tables

Elena Kondrashova November 4, 2022

Hello Community!

I have two tables:

Screenshot 2022-11-04 222516.jpg

I am using a table filter macro to calculate SUM of hours in each of the columns: Downtime, Overtime and Working Hours. 

Screenshot 2022-11-04 222612.jpg 

I am trying to figure out if there's a way to join these two tables, so I can

a) see the total of Downtime, Overtime and Working Hours per Month in a single table;

b) use a formula & build a chart that would show what is the percentage of Downtime (60 hrs) out of the Total working hours (70 hrs) for the Month of October.

 

Thank you for your insights! 

Elena

2 answers

4 votes
Luis Machado
Community Champion
November 4, 2022

Hi @Elena Kondrashova

Assuming you're using Table Filter and Charts from StillSoft, you can use the table transformer macro to accomplish this: https://docs.stiltsoft.com/display/TFAC/How+to+use+Table+Transformer+macro

Use the "lookup Tables" preset and match records by the project column.

Elena Kondrashova November 5, 2022

Hi Luis,

Thank you for your response! Yes, I am trying to use table transformer with table lookup option, but getting a bit stuck.
The reason: my first table can have multiple rows for October for Project A, while my second table will always have only one row for October for Project A.
When I try to join these tables, it duplicates the October row from my second table, for every October row I have in the first table. I can’t figure out how to avoid this duplication. 

Luis Machado
Community Champion
November 6, 2022

Hi Elena,

I see the problem. So because your rows have unique data, they will always have their own unique row in the table and the Lookup Table preset will match the duplicates. What you'd have to do is remove the unique values that cause the duplicates.

The Columns responsible for that currently are Date, Overtime, and Downtime.

Overtime and Downtime you could potentially work around by using the SUM() function to add the values from each row in a Month.

Date unfortunately is not something you'd be able to remedy, and it would need to be removed from the dataset to get the end result you want. If Date is required, I don't believe you'll be able to avoid some amount of duplicates.

So the first thing would be to wrap your table with the duplicate entries in a custom Table Transformer with the following SQL:

SELECT 'Project' as 'Project', 'Month', SUM(Overtime) as 'Overtime', SUM(Downtime) as 'Downtime'
FROM T1
GROUP BY 'Project', 'Month'
ORDER BY 'Project'

Which gives you the following result:

image (1).png

Then you nest that macro into another macro on the page that also has the second table in it. The query for the outer macro would look something like this:

SELECT *
FROM T1
OUTER JOIN T*
ON T1.'Project' = T*.'Project' AND T1.'Month' = T*.'Month'

In the edit view it looks like this:

image (2).png

and the end result looks like this:

image (3).png

If the dates are necessary, you could potentially have Table 1 live somewhere else and call it into your macro using the Table Excerpt and Table Excerpt Include macros. Then the table could exist with the dates in one view and without them in another so you don't have to duplicate keeping track of the same data.

Finally a word of caution, nesting macros like this can eventually lead to performance impacts depending on how much data you're running your calculations against. The more complex your build the higher the potential, so I would recommend keeping it simple where you can. Hope this helps!

Like Elena Kondrashova likes this
Elena Kondrashova November 8, 2022

Thank you @Luis Machado  really appreciate detailed response! I've tried to make suggested changes, and I think it worked. I do feel like the page takes time to load, so I will keep an eye on performance. Once again thanks a lot for your help.

Like Luis Machado likes this
2 votes
Natalie Paramonova _Stiltsoft_
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.
November 9, 2022

Hi @Elena Kondrashova ,


Thanks to @Luis Machado  - you have almost the whole case done!

To wrap everything, I can suggest the following structure:

Mon 15-1.png

The query for the internal Table Transformer macro is left as it is.

The query for the external Table Transformer macro is as following:

SELECT *,
'Working Hours' - 'Downtime' as 'Not Downtime'
FROM
(SELECT *
FROM T1
OUTER JOIN T*
ON T1.'Project' = T*.'Project' AND T1.'Month' = T*.'Month')

We’ll be using the new “Not Downtime” column later for our chart.

Here is the outcome of our macro:

Mon 15-2.png

The next step is to filter your table by month and count the required totals:

Mon 15-3.png

The last step is to build your chart:

Mon 15-4.png

Mon 15-5.png

Note that if you need to see the whole table with all the totals somewhere on the page, as @Luis Machado  has kindly mentioned before, use the Table Excerpt/Table Excerpt Include macros. For example, place your Table Excerpt between the external Table Transformer and Table Filter macros.

As your hosting is not specified, note that our screenshots were taken for Confluence Server/Data Center. For Cloud you’ll need to nest macros via the Table Toolbox.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events