Forum Discussion
AllanT1495
Feb 02, 2024Copper Contributor
Change data set structure, unsure how to transform this
I have a dataset that isn't structured ideally. I'm hoping someone can suggest a way to transform this. Current structure has different Gate purpose dates across in columns. Col1text-Projec...
- Feb 02, 2024
It could be done with Power Query
please see in attached file.
If with formulae it depends on which Excel platform/version you are and how big the source data.
PeterBartholomew1
Feb 02, 2024Silver Contributor
That appear to be a classic 'unpivot' operation and the best point at which to apply it is often within PowerQuery before the data is ever loaded to Excel. Now however, Excel itself is reasonably capable when it comes to such restructuring (normalisation) processes. The basic function to apply is TOCOL
= TOCOL(date)but, assuming you also want the row and column headers to appear, this becomes
= LET(
p, IF(date, project),
g, IF(date, gate),
HSTACK(TOCOL(p), TOCOL(g), TOCOL(date))
)where the formula assumed 'date' to be datevalues and contain no blanks. If there are blanks, the next step is
= LET(
p, IF(date, project, NA()),
g, IF(date, gate, NA()),
HSTACK(TOCOL(p,3), TOCOL(g,3), TOCOL(date,1))
)As an aside, to reverse the process using the insider version of 365
= LET(
project, CHOOSECOLS(unpivotted, 1),
gate, CHOOSECOLS(unpivotted, 2),
date, CHOOSECOLS(unpivotted, 3),
PIVOTBY(project, gate, date, MAX, , 0, , 0)
)