Table Filter Macro using Variable as Input
Asked by Emily Berg:

I have several pages that I need to create that reference the same table excerpt. Within the header of the Confluence page I would like to include the inputs for filter the table (so I don't have to edit the macro for each page). Is there way to reference a variable within a Filter Table macro? In this example, I would like to filter the table based on "Unit #" column. And my input is "Alpha-2".

![2021-06-24_14-26-21.png](/t5/image/serverpage/image-id/148849iCB0FCCEF9DC94513/image-size/large?v=v2&px=999 "2021-06-24_14-26-21.png")


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

If I got your case right, you reuse the source table and wrap every Table Excerpt Include macro into the Table Filter macro to filter by different columns and values (so you'll get a kind of a dashboard).

Unfortunately, we don't have any automatic rules to assign filters/values to the Table Filter macro based on additional tables or smth similar.

comments: author: Emily Berg
body: Hi [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) ,

Okay fair enough. How about if I wrap the Table Excerpt into a Table Transformer Macro and "filter" the table that way - could I use a page variable to reference in the SQL query to extract a line(s) of interest?

Emily


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

The Table Transformer macro can use a page variable in its SQL query:

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

SELECT T1.\* FROM T1  
WHERE T1.'Name' = (SELECT T2.'Variable' FROM T2)

The big source table can be reused and inserted via the Table Excerpt Include macro. But you'll still need to wrap your reused table into the Table Transformer and create a mini-table with a different value for all your pages.

It seems that it is not faster than manually filtering you table with the Table Filter macro.

Have I got your case right? You need to have different values for every page?

If you want to show the same filtered table on all of your pages, then you'll need to set your filter once and wrap both your source table and the Table Filter macro on top of it into the Table Excerpt macro.


author: Emily Berg
body: Thank you [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) ,

Yes, this is what I was going for, but I was hoping to be able to reference a variable outside of the table transformer macro - like maybe within the page's properties macro? I am trying to prevent an error when typing text and then having to select the proper filter (duplicate entries).

Emily


author: Katerina Kovriga {Stiltsoft}
body: You may create several mini-tables with variables and wrap every one into the Table Excerpt with a corresponding name.

Then you'll be able to include it into the Table Transformer macro via the Table Excerpt Include macro.


author: Emily Berg
body: [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746)

Thank you for this comment - it allowed me to be a bit more creative about how I approach this. I found a solution that works beautifully, using multiple table excerpts across various pages. Awesome, thank you!

Emily


author: Katerina Kovriga {Stiltsoft}
body: And thank you for reaching out!


author: Emily Berg
body: [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) - Hello!

I am now using this in a different use case and am wondering about accessing the column of interest as a variable too.

![2021-11-10_11-24-57.png](https://community.atlassian.com/t5/image/serverpage/image-id/168794iB47E21DFB9C7BD17/image-size/large?v=v2&px=999 "2021-11-10_11-24-57.png")

With something like this...

SELECT \* FROM T1  
WHERE (SELECT T2.'Column' FROM T2) = (SELECT T2.'Variable' FROM T2)

Thank you for your assistance!

Emily


author: Katerina Kovriga {Stiltsoft}
body: Hi [@Emily Berg](/t5/user/viewprofilepage/user-id/4210574) , I'm afraid it is not possible to introduce a column name as a variable.


author: Emily Berg
body: Thank you for the fast response [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) !


author: Anna Szab?
body: Hi [@Emily Berg](/t5/user/viewprofilepage/user-id/4210574) you can try to transpose the table with a Table Transfo macro fisrt, then after the filtering transfpose it back.

[@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) Thank you for the great answer! Do you know if there is a way to use it for multiple Variables on the same table? Like when I add an extra line on the Variable table (want to filter on B and C too) it only filters on the first one.


author: Katerina Kovriga {Stiltsoft}
body: Hi [@Anna Szab?](/t5/user/viewprofilepage/user-id/4651798) ,

You may add additional columns for your extra variables to the second table:

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

Here is your modified SQL query:

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

SELECT T1.\* FROM T1  
WHERE T1.'Name' = (SELECT T2.'Variable 1' FROM T2)  
OR T1.'Name' = (SELECT T2.'Variable 2' FROM T2)

And here is the result:

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

Hope this helps your case.


author: Anna Szab?
body: [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) It answers my question! Thank you for the unbeliavebly quick answer!!!


Tags: confluence-server

filter

server

table-filter