Combine two table using table transformer and filter showing the next Milestone
Asked by Deborah Frommer:

Hi all,

I have two tables:

- One table is a list of ongoing project with Project Manager and Project Status  
![Projects.png](https://community.atlassian.com/t5/image/serverpage/image-id/275861iAE6DE043811CFAA5/image-size/large?v=v2&px=999 "Projects.png")

- The other is a table with project milestones of the projects![Milestones.png](https://community.atlassian.com/t5/image/serverpage/image-id/275862iB7DB22E05F8E20C6/image-size/large?v=v2&px=999 "Milestones.png")

As a result I would like to have a list with the projects and next Milestone

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

The difficulty is, that two Milestones can be on the same day and then I have to merge the cell. Thats I tried with CONCAT or with Group

The other issue I have is, that I can filter the older Milestones (older than today), but how can I only filter the next Milestone?

Many thanks for your help


Answers:
author: Stiltsoft support
body: Hi [@Deborah Frommer](/t5/user/viewprofilepage/user-id/5199858) ,

Hope the following solution will help your case:

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

Here is the SQL query for the internal Table Transformer macro:

SELECT \*,  
MIN('Days')  
FROM  
(SELECT \*,  
DATEDIFF(day, "today", 'Milestone-Date') AS 'Days'  
FROM  
(SELECT 'Project', 'Milestone', 'Milestone-Date' FROM  
(SELECT T1.'Project',  
SUM(T1.'Milestone' + " ") AS 'Milestone',  
T1.'Milestone-Date'  
FROM T\*  
GROUP BY 'Project', 'Milestone-Date')  
WHERE 'Milestone-Date' \> "today"))  
GROUP BY 'Project'

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

What we do here:

SELECT T1.'Project',  
SUM(T1.'Milestone' + " ") AS 'Milestone',  
T1.'Milestone-Date'  
FROM T\*  
GROUP BY 'Project', 'Milestone-Date' - we group milestones that belong to the same project and have the same date

SELECT 'Project', 'Milestone', 'Milestone-Date' FROM  
...  
WHERE 'Milestone-Date' \> "today" - we filter out milestones that have already passed

SELECT \*,  
DATEDIFF(day, "today", 'Milestone-Date') AS 'Days'  
FROM ... - we count days difference between "today" and the Milestone-Date. Please make sure that in the Settings tab of your Table Transformer macro you have the correct date format. For our example it will be **d M yy**.

SELECT \*,  
MIN('Days')  
FROM  
...  
GROUP BY 'Project' - here we select the next milestone (the minimum days difference).

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

SELECT T1.'Project', 'PM', 'Status',  
'Milestone' AS 'Next Milestone',  
'Milestone-Date'  
FROM T1 OUTER JOIN T2 ON T1.'Project' = T2.'Project'

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

Here we simply use the standard Look up preset but list the required columns that we want to display.

By the way, you may try to visualize your data with the help of our advanced [Gantt Chart](https://docs.stiltsoft.com/tfac/dc-server/gantt-chart-type-42239634.html?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111). It allows you to show milestones and events as well.

comments: author: Deborah Frommer
body: That's an great solution.

Many thanks for your quick help!


Tags: confluence-server

filter

ms-excel

server

table