Forum Discussion

Chetanab's avatar
Chetanab
Microsoft Employee
5 years ago
Solved

Unpivoting multiple date columns

Hi,

 

I have a table like this - 

 

TitleRequest Start DateRequest End DateTargeted Start DateTargeted End DateActual Start DateActual End Date
Item 17/30/20219/30/20217/30/20219/30/20215/30/20217/30/2021
Item 27/30/20219/30/20217/30/20219/30/20215/30/2021

7/30/2021

 

I need to transform it to something like this

TitleDate CategoryStart DateEnd Date
Item 1Request Date7/30/20219/30/2021
Item 1Targeted Date7/30/20219/30/2021
Item 1Actual Date5/30/20217/30/2021
Item 2Request Date7/30/20219/30/2021
Item 2Targeted Date7/30/20219/30/2021
Item 2Actual Date5/30/20217/30/2021

 

I tried unpivoting all the start date columns and the end date columns from the first table but that gives me a cartesian product. IS there a way to do thi

  • Select the first column. Unpivot the othe columns.

    Split the centre column (by space, once as far left as possible)

    Select the new column that has 'start date' and 'end date' in it. Pivot this column. Choose Value(the date column) as Values. Choose Don't Aggregate from the advanced.

    That should be it.

2 Replies

  • HotChilli's avatar
    HotChilli
    Community Champion

    Select the first column. Unpivot the othe columns.

    Split the centre column (by space, once as far left as possible)

    Select the new column that has 'start date' and 'end date' in it. Pivot this column. Choose Value(the date column) as Values. Choose Don't Aggregate from the advanced.

    That should be it.