table transformer to do calculations based on previous row
Asked by emagnun:

I'm trying to do a very basic calculation to find my sprint weight% and Progress% based on my sprint plan.

Below is my table. Now, how do i calculate the data here?

Sprint Weight %= (Features Planned in the specific sprint / total features in all sprints)\*100

Progress% = Current Sprint weight + Previous progress %

![Capture.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/170438i5546366591281B96/image-dimensions/305x281?v=v2 "Capture.JPG")

From a simple xls file, i can get my values as below. I have no clue how to achieve it in confluence.

![Capture.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/170440i9DEC07F518600E5D/image-dimensions/365x202?v=v2 "Capture.JPG")


Answers:
author: Katerina Kovriga {Stiltsoft}
body: Hi [@emagnun](/t5/user/viewprofilepage/user-id/4359249) ,

I've consulted with our developers, and they provided me with a better solution for your case based on the two Table Transformer macros:

![Tue 1-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/170533i78EB97CB7E1A01CA/image-size/large?v=v2&px=999 "Tue 1-1.png")

Here is the SQL query for the first Table Transformer macro that is inside:

SELECT \*,  
'Features Planned' / (SELECT SUM(T1.'Features Planned') FROM T1) \* 100 AS 'Sprint Weight, %'  
FROM T1

![Tue 1-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/170534i540F1C2E104FE4EC/image-size/large?v=v2&px=999 "Tue 1-2.png")

![Tue 1-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/170535i0B7764C861DBCB95/image-size/large?v=v2&px=999 "Tue 1-3.png")

And here is the SQL query for the second Table Transformer macro:

SELECT \*,  
(SELECT SUM(TT2.'Sprint Weight, %') FROM T1 as TT2 WHERE TT2.'Sprint' \<= TT1.'Sprint')  
AS 'Progress, %'  
FROM T1 AS TT1

![Tue 1-4.png](https://community.atlassian.com/t5/image/serverpage/image-id/170536i1B12793D65CB331F/image-size/large?v=v2&px=999 "Tue 1-4.png")

Everything seems to work as it's shown on your screenshots.

comments: author: emagnun
body: This is interesting. Thanks.


author: Katerina Kovriga {Stiltsoft}
body: Hi [@emagnun](/t5/user/viewprofilepage/user-id/4359249) ,

The Table Transformer macro doesn't allow you to refer to specific cells, it operates with table columns.

Of course, you'll be able to count the cumulative totals via the [Pivot Table](https://docs.stiltsoft.com/display/public/TFAC/Managing+pivot+table+options#Managingpivottableoptions-Enablethecumulativecount) macro or the [Table Transformer](https://docs.stiltsoft.com/display/public/TFAC/Custom+Transformation+-+use+cases+with+advanced+SQL+queries#CustomTransformationusecaseswithadvancedSQLqueries-Calculatingcumulative(running)totals) macro, but I'm afraid that such formulas where you use any previously calculated cells from the same column are not possible as for now. The Spreadsheet macro is on our roadmap and we hope to release it in 2-3 months.

Maybe I can suggest using the [Table from CSV](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+from+CSV+macro) macro - you'll be able to [connect your Google Spreadsheet via a URL](https://docs.stiltsoft.com/display/public/TFAC/Outputting+tables+from+Google+Sheets+and+Google+Drive+in+Confluence) to Confluence and proceed to filter/visualize your already aggregated data as a regular table.

comments: author: emagnun
body: We would love to see the spreasheet macro soon.


Tags: confluence-server

server

table-transformer