Special Unpivot Columns

johnmpl

Board Regular
Joined
Jun 14, 2013
Messages
237
Office Version
  1. 365
Platform
  1. Windows
Hi, to all!

I need to special unpivot some data.

Input:

[TABLE="width: 734"]
<colgroup><col span="3"><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]NAMEA[/TD]
[TD]NAMEB[/TD]
[TD]NAMEC[/TD]
[TD]DATE THING 1[/TD]
[TD]DESCRIPTION[/TD]
[TD]DATE THING 2[/TD]
[TD]DESCRIPTION 2[/TD]
[TD]DATE THING 3[/TD]
[TD]DESCRIPTION 3[/TD]
[/TR]
[TR]
[TD]Name1[/TD]
[TD]Name28[/TD]
[TD]Name55[/TD]
[TD="align: right"]28/01/2019[/TD]
[TD]Descript 1[/TD]
[TD="align: right"]24/02/2019[/TD]
[TD]Descript 28[/TD]
[TD="align: right"]23/03/2019[/TD]
[TD]Descript 55[/TD]
[/TR]
[TR]
[TD]Name2[/TD]
[TD]Name29[/TD]
[TD]Name56[/TD]
[TD="align: right"]29/01/2019[/TD]
[TD]Descript 2[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]24/03/2019[/TD]
[TD]Descript 56[/TD]
[/TR]
[TR]
[TD]Name3[/TD]
[TD]Name30[/TD]
[TD]Name57[/TD]
[TD="align: right"]30/01/2019[/TD]
[TD]Descript 3[/TD]
[TD="align: right"]26/02/2019[/TD]
[TD]Descript 30[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Name4[/TD]
[TD]Name31[/TD]
[TD]Name58[/TD]
[TD="align: right"]31/01/2019[/TD]
[TD]Descript 4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Name5[/TD]
[TD]Name32[/TD]
[TD]Name59[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]28/02/2019[/TD]
[TD]Descript 32[/TD]
[TD="align: right"]27/03/2019[/TD]
[TD]Descript 59
[/TD]
[/TR]
</tbody>[/TABLE]


Output:

[TABLE="width: 388"]
<colgroup><col><col span="2"><col span="2"><col></colgroup><tbody>[TR]
[TD]NAMEA[/TD]
[TD]NAMEB[/TD]
[TD]NAMEC[/TD]
[TD]TYPE[/TD]
[TD]DATE[/TD]
[TD]DESCRIPTION[/TD]
[/TR]
[TR]
[TD]Name1[/TD]
[TD]Name28[/TD]
[TD]Name55[/TD]
[TD]THING 1[/TD]
[TD="align: right"]28/01/2019[/TD]
[TD]Descript 1[/TD]
[/TR]
[TR]
[TD]Name1[/TD]
[TD]Name28[/TD]
[TD]Name55[/TD]
[TD]THING 2[/TD]
[TD="align: right"]24/02/2019[/TD]
[TD]Descript 28[/TD]
[/TR]
[TR]
[TD]Name1[/TD]
[TD]Name28[/TD]
[TD]Name55[/TD]
[TD]THING 3[/TD]
[TD="align: right"]23/03/2019[/TD]
[TD]Descript 55[/TD]
[/TR]
[TR]
[TD]Name2[/TD]
[TD]Name29[/TD]
[TD]Name56[/TD]
[TD]THING 1[/TD]
[TD="align: right"]29/01/2019[/TD]
[TD]Descript 2[/TD]
[/TR]
[TR]
[TD]Name2[/TD]
[TD]Name29[/TD]
[TD]Name56[/TD]
[TD]THING 3[/TD]
[TD="align: right"]24/03/2019[/TD]
[TD]Descript 56[/TD]
[/TR]
[TR]
[TD]Name3[/TD]
[TD]Name30[/TD]
[TD]Name57[/TD]
[TD]THING 1[/TD]
[TD="align: right"]30/01/2019[/TD]
[TD]Descript 3[/TD]
[/TR]
[TR]
[TD]Name3[/TD]
[TD]Name30[/TD]
[TD]Name57[/TD]
[TD]THING 2[/TD]
[TD="align: right"]26/02/2019[/TD]
[TD]Descript 30[/TD]
[/TR]
[TR]
[TD]Name4[/TD]
[TD]Name31[/TD]
[TD]Name58[/TD]
[TD]THING 1[/TD]
[TD="align: right"]31/01/2019[/TD]
[TD]Descript 4[/TD]
[/TR]
[TR]
[TD]Name5[/TD]
[TD]Name32[/TD]
[TD]Name59[/TD]
[TD]THING 2[/TD]
[TD="align: right"]28/02/2019[/TD]
[TD]Descript 32[/TD]
[/TR]
[TR]
[TD]Name5[/TD]
[TD]Name32[/TD]
[TD]Name59[/TD]
[TD]THING 3[/TD]
[TD="align: right"]27/03/2019[/TD]
[TD]Descript 59[/TD]
[/TR]
</tbody>[/TABLE]

Appreciate all your help. Blessings!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#70AD47]NAMEA[/td][td=bgcolor:#70AD47]NAMEB[/td][td=bgcolor:#70AD47]NAMEC[/td][td=bgcolor:#70AD47]Type[/td][td=bgcolor:#70AD47]Date[/td][td=bgcolor:#70AD47]Description[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name1[/td][td=bgcolor:#E2EFDA]Name28[/td][td=bgcolor:#E2EFDA]Name55[/td][td=bgcolor:#E2EFDA]THING 1[/td][td=bgcolor:#E2EFDA]
28/01/2019​
[/td][td=bgcolor:#E2EFDA]Descript 1[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name1[/td][td]Name28[/td][td]Name55[/td][td]THING 1[/td][td]
28/01/2019​
[/td][td]Descript 28[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name1[/td][td=bgcolor:#E2EFDA]Name28[/td][td=bgcolor:#E2EFDA]Name55[/td][td=bgcolor:#E2EFDA]THING 1[/td][td=bgcolor:#E2EFDA]
28/01/2019​
[/td][td=bgcolor:#E2EFDA]Descript 55[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name1[/td][td]Name28[/td][td]Name55[/td][td]THING 2[/td][td]
24/02/2019​
[/td][td]Descript 1[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name1[/td][td=bgcolor:#E2EFDA]Name28[/td][td=bgcolor:#E2EFDA]Name55[/td][td=bgcolor:#E2EFDA]THING 2[/td][td=bgcolor:#E2EFDA]
24/02/2019​
[/td][td=bgcolor:#E2EFDA]Descript 28[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name1[/td][td]Name28[/td][td]Name55[/td][td]THING 2[/td][td]
24/02/2019​
[/td][td]Descript 55[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name1[/td][td=bgcolor:#E2EFDA]Name28[/td][td=bgcolor:#E2EFDA]Name55[/td][td=bgcolor:#E2EFDA]THING 3[/td][td=bgcolor:#E2EFDA]
23/03/2019​
[/td][td=bgcolor:#E2EFDA]Descript 1[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name1[/td][td]Name28[/td][td]Name55[/td][td]THING 3[/td][td]
23/03/2019​
[/td][td]Descript 28[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name1[/td][td=bgcolor:#E2EFDA]Name28[/td][td=bgcolor:#E2EFDA]Name55[/td][td=bgcolor:#E2EFDA]THING 3[/td][td=bgcolor:#E2EFDA]
23/03/2019​
[/td][td=bgcolor:#E2EFDA]Descript 55[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name2[/td][td]Name29[/td][td]Name56[/td][td]THING 1[/td][td]
29/01/2019​
[/td][td]Descript 2[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name2[/td][td=bgcolor:#E2EFDA]Name29[/td][td=bgcolor:#E2EFDA]Name56[/td][td=bgcolor:#E2EFDA]THING 1[/td][td=bgcolor:#E2EFDA]
29/01/2019​
[/td][td=bgcolor:#E2EFDA]Descript 56[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name2[/td][td]Name29[/td][td]Name56[/td][td]THING 3[/td][td]
24/03/2019​
[/td][td]Descript 2[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name2[/td][td=bgcolor:#E2EFDA]Name29[/td][td=bgcolor:#E2EFDA]Name56[/td][td=bgcolor:#E2EFDA]THING 3[/td][td=bgcolor:#E2EFDA]
24/03/2019​
[/td][td=bgcolor:#E2EFDA]Descript 56[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name3[/td][td]Name30[/td][td]Name57[/td][td]THING 1[/td][td]
30/01/2019​
[/td][td]Descript 3[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name3[/td][td=bgcolor:#E2EFDA]Name30[/td][td=bgcolor:#E2EFDA]Name57[/td][td=bgcolor:#E2EFDA]THING 1[/td][td=bgcolor:#E2EFDA]
30/01/2019​
[/td][td=bgcolor:#E2EFDA]Descript 30[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name3[/td][td]Name30[/td][td]Name57[/td][td]THING 2[/td][td]
26/02/2019​
[/td][td]Descript 3[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name3[/td][td=bgcolor:#E2EFDA]Name30[/td][td=bgcolor:#E2EFDA]Name57[/td][td=bgcolor:#E2EFDA]THING 2[/td][td=bgcolor:#E2EFDA]
26/02/2019​
[/td][td=bgcolor:#E2EFDA]Descript 30[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name4[/td][td]Name31[/td][td]Name58[/td][td]THING 1[/td][td]
31/01/2019​
[/td][td]Descript 4[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name5[/td][td=bgcolor:#E2EFDA]Name32[/td][td=bgcolor:#E2EFDA]Name59[/td][td=bgcolor:#E2EFDA]THING 2[/td][td=bgcolor:#E2EFDA]
28/02/2019​
[/td][td=bgcolor:#E2EFDA]Descript 32[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name5[/td][td]Name32[/td][td]Name59[/td][td]THING 2[/td][td]
28/02/2019​
[/td][td]Descript 59[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Name5[/td][td=bgcolor:#E2EFDA]Name32[/td][td=bgcolor:#E2EFDA]Name59[/td][td=bgcolor:#E2EFDA]THING 3[/td][td=bgcolor:#E2EFDA]
27/03/2019​
[/td][td=bgcolor:#E2EFDA]Descript 32[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Name5[/td][td]Name32[/td][td]Name59[/td][td]THING 3[/td][td]
27/03/2019​
[/td][td]Descript 59[/td][/tr]
[/table]


Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"NAMEA", type text}, {"NAMEB", type text}, {"NAMEC", type text}, {"DATE THING 1", type datetime}, {"DESCRIPTION", type text}, {"DATE THING 2", type datetime}, {"DESCRIPTION 2", type text}, {"DATE THING 3", type datetime}, {"DESCRIPTION 3", type text}}),
    #"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type", {"DATE THING 1", "DATE THING 2", "DATE THING 3"}, "Attribute", "Value"),
    #"Unpivoted Only Selected Columns1" = Table.Unpivot(#"Unpivoted Only Selected Columns", {"DESCRIPTION", "DESCRIPTION 2", "DESCRIPTION 3"}, "Attribute.1", "Value.1"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Only Selected Columns1",{{"Attribute", "Type"}, {"Value", "Date"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Attribute.1"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns",{{"Value.1", "Description"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns1",{{"Date", type date}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1","DATE ","",Replacer.ReplaceText,{"Type"})
in
    #"Replaced Value"[/SIZE]

now you can sort / filter / remove duplicates from description or whatever you want
 
Upvote 0
Thx Sandy for your answer.

If you remove duplicates, Descript28 is related to THING 1, when this must be in THING 2. Same thing with Descript55, must be with THING 3. How can I get the correct result? Blessings!
 
Upvote 0
you need to try yourself with columns selection and remove duplicates
I did unpivot as you wanted but the rest is up to you

remove duplicates from Description only is not mandatory :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top