I need to insert a formula within a Confluence table to return a value based on two dates
Asked by Pam Larson:

I am new to Confluence. I want to use Confluence to track goals - completion date vs. target date. If the completion date is within five days, I want to indicate that it is "On Time" in green; if it's more than 5 days late, but less than 10 days, I want to indicate that it is "Late" in yellow; and if it's more than 10 days, I want to indicate that it is "Very Late" in red.

Can this be done and can you help me with the formula or direct me to the information that I need to figure this out on my own?


Answers:
author: Katerina Kovriga {Stiltsoft}
body: Hi there,

As this question mentions our [Table Filter and Charts for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-and-charts-for-confluence?tab=overview&hosting=cloud&utm_source=atl_community) app, we are happy to introduce its new macro -- [Table Spreadsheet](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Spreadsheet+macro?utm_source=atl_community).

This new macro allows you to work with fully functional Excel spreadsheets right in Confluence.

You'll be able to use cells' formulas, filters, conditional formatting, etc., create pivot tables and charts from the page view and edit mode.

![](https://docs.stiltsoft.com/download/attachments/83100938/Conditional%20formatting.png?version=1&modificationDate=1641987630000&api=v2&effects=border-simple,shadow-kn)

The Table Spreadsheet macro is available for Cloud and Server/Data Center.


author: Natalie Paramonova [Stiltsoft]
body: Hi Pam,

You can do this with the help of the [Table Transformer](https://docs.stiltsoft.com/display/TableFilter/How+to+use+Table+Transformer+macro) macro (one of the macros bundled in the [Table Filter and Charts](https://marketplace.atlassian.com/apps/27447/table-filter-and-charts-for-confluence?hosting=cloud&tab=overview) app). The macro allows performing complex calculations using SQL queries.

Here is an example.

Place two tables in the macro body. The first table is your source table with dates columns. The second one is a table with colored statuses.

![2019-07-19_10h39_15.png](https://community.atlassian.com/t5/image/serverpage/image-id/60922i044044CC90E54BF8/image-dimensions/540x357?v=v2 "2019-07-19_10h39_15.png")

Edit the macro and switch to the SQL query tab. Use the following query:

SELECT \*, CASE WHEN (('Completion date' - 'Target date') / "24h") \< 5 THEN "ON TIME" WHEN (('Completion date' - 'Target date') / "24h") \> 5 AND (('Completion date' - 'Target date') / "24h") \<= 10 THEN "LATE" ELSE "VERY LATE" END AS 'Rating' FROM T1

![2019-07-19_10h39_50.png](https://community.atlassian.com/t5/image/serverpage/image-id/60923iE09CAE41365C8430/image-dimensions/588x333?v=v2 "2019-07-19_10h39_50.png")

Set the correct date format in the Settings tab.

![2019-07-19_11h41_12.png](https://community.atlassian.com/t5/image/serverpage/image-id/60924i30ECE37A663741D4/image-dimensions/586x327?v=v2 "2019-07-19_11h41_12.png")

The result is as follows.

![2019-07-19_10h38_25.png](https://community.atlassian.com/t5/image/serverpage/image-id/60921i6BB6BDC422195D9A/image-dimensions/470x256?v=v2 "2019-07-19_10h38_25.png")

You can use a manually created table, the Jira Issues or other native Confluence macros outputting tables as a source table.

comments: author: Gireesha Jeera
body: [@Natalie Paramonova \[Stiltsoft\]](/t5/user/viewprofilepage/user-id/1779341)

i have managed to create table for similar requirement, but how color of the text changes in Rating column based on the value ?

can you send details on this please ?

- Gireesh


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

You need to have two tables wrapped in the Table Transformer macro:

1. The table with date columns
2. The small table with the required ratings

The second table is created with the help of the standard [Status](https://confluence.atlassian.com/doc/status-macro-223222355.html) macro. It is often used to indicate the result or progress of different projects. When you create a status, you specify its name and the color of the lozenge.

![](https://confluence.atlassian.com/doc/files/223222355/1005333705/1/1589961927646/Status-params.png)

Now if you go back to the SQL query, you may notice that we have a condition when to use this or that status based on the difference between the two dates from the first table and the name of the particular status:

SELECT \*, CASE WHEN (('Completion date' - 'Target date') / "24h") \< 5 THEN "**ON TIME**" WHEN (('Completion date' - 'Target date') / "24h") \> 5 AND (('Completion date' - 'Target date') / "24h") \<= 10 THEN "**LATE** " ELSE "**VERY LATE**" END AS 'Rating' FROM T1

As a result, we add an extra colored Ratings column to the first table based on the query.

Hope I've cleared this moment for you.


author: Gireesha Jeera
body: [@Natalie Paramonova \[Stiltsoft\]](/t5/user/viewprofilepage/user-id/1779341)

Thanks a lot, it really helped. appreciate quick help.

Regards,

Gireesh


author: Gireesha Jeera
body: morning [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) ,

what if i want to compare with the current date with the Target date ? how to take current date for the same query above.

Regards,

Gireesh


author: Katerina Kovriga {Stiltsoft}
body: Hi [@Gireesha Jeera](/t5/user/viewprofilepage/user-id/4028302)

Use the "today" function:

SELECT \*, CASE WHEN ("today" - 'Target date') / "24h" \< 5 THEN "ON TIME"  
WHEN ("today" - 'Target date') / "24h" \> 5 AND  
("today" - 'Target date') / "24h" \<= 10 THEN "LATE"  
ELSE "VERY LATE" END AS 'Rating' FROM T1


author: Gireesha Jeera
body: Thanks [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) That worked perfectly. thank you once again.


Tags: cloud

jira-cloud