Rename Column Header based on Value from Second Table / Variable

Emily Berg June 9, 2022

Hello,

I would like to rename a column based on a value from a second table.  Is something like this possible? @Katerina Kovriga _Stiltsoft_ - I have copied you because you have been able to answer a bunch of my previous questions.

Thank you!

Emily

2022-06-09_7-02-47.png

1 answer

1 vote
Katerina Kovriga _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.
June 9, 2022

Hi @Emily Berg ,

I've been also puzzled with the case, but our developers found a solution using the PIVOT table function:

Thu 4-1.png

SELECT * FROM (
SELECT * FROM T1 LEFT JOIN T2 ON T2.'Index' = 2
)
PIVOT (FIRST('Key') for 'Header Key')

Thu 4-2.png

Seems that I've got your case right from the screenshot: we go to the second table, use a condition, select a value based on it and rename the column from the first table - the new name matches this value.

The additional "Index" column can be further hidden with the help of the Table Filter macro or additional Table Transformer macro.

Emily Berg June 9, 2022

@Katerina Kovriga _Stiltsoft_ - this is so great, thank you!  Let's see if we can go a step further - can we do multiple column header changes as once or do I need to wrap in multiple transformers?

SELECT *
FROM
(SELECT * FROM T1 LEFT JOIN T2 ON T2.'Index' = 1)
PIVOT(FIRST('Key') for 'Key Column', (FIRST('Summary') for 'Summary Column'))

Thank you!

Emily

Katerina Kovriga _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.
June 9, 2022

I don't think that the PIVOT function supports multiple aggregation under one command. So you may use several Table Transformer macros and repeat the original query with different column names and conditions.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events