How do I reverse "Transpose" my data?

Does anyone know what is the best way to REVERSE/INVERSE the TRANSPOSE. Is this possible to do? Basically I want to turn the ID (with 3 rows) and turn it into a single row.

Note: I do have powerquery (for transposing data)

Below is my RAW data

ID Quarter Total Sales Visits base on HRS Q1 Q2 visit list Q3 Visit list Quarterly Total Hrs Sum of Store Hours
Count of Store Visits
23749 Q1 37 Visits Yes 2.1 2.1 2
23749 Q2 81 Visits Yes 0.9 0.9 1
23749 Q3 34 Visits Yes 0.7 0.7 1
23826 Q1 4 No Visits
23826 Q2 13 No Visits
23826 Q3 34 Visits Yes 0.8 0.8 1

My Goals is to REVERSE/INVERSE the transpose into ONE/SINGLE row.

ID Q1 Sales Q2 Sales Q3 Sales Q1 visit Q2 visit list Q3 Visit list Quarterly Total Hrs Quarterly Total Hrs Quarterly Total Hrs Count of Store Visits Count of Store Visits
Count of Store Visits
23749 37 81 34 Yes Yes Yes 2.1 0.9 0.7 2 1 1
23826 4 13 34 Yes 0.8 1 1

Answer
Answer

Hi

With Get & Transform/Power Query. I had to fix your data (in red and green below). My dec. separator is the comma

Image

Not sure I understand why you want the Qtr Visit columns with Yes/null as if you have a Count of Visits…

Query code:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    RemovedColumns = Table.RemoveColumns(Source,{"Visits base on HRS","Quarterly Total Hrs"}),
    outColumnOrder =
        {"ID",
         "Q1 Sales","Q2 Sales","Q3 Sales","Q4 Sales",
         "Q1 Visit","Q2 Visit","Q3 Visit","Q4 Visit",
         "Q1 Store Hours","Q2 Store Hours","Q3 Store Hours","Q4 Store Hours",
         "Q1 Store Visits","Q2 Store Visits","Q3 Store Visits","Q4 Store Visits"
        },
    textToRemove = List.Buffer({"Total ","Sum of ","Count of "}),
    GroupedRows = Table.Group(RemovedColumns, {"Quarter"}, {{"GRP_Quarter", each _, type table}}),
    Tranformed = Table.TransformColumns(GroupedRows,
        {"GRP_Quarter", each
            let
                quarter = List.First([Quarter]),
                columnNames = Table.ColumnNames(_),
                visitColumns = List.Select(columnNames, each Text.Contains(_,"visit list",Comparer.OrdinalIgnoreCase)),
                notInQuarter = List.Select(visitColumns, each not Text.StartsWith(_,quarter)),
                removedColumns = Table.RemoveColumns(_,notInQuarter & {"Quarter"}),
                inQuarter = List.Select(visitColumns, each Text.StartsWith(_,quarter)),
                renamedColumn = Table.RenameColumns(removedColumns, {{List.First(inQuarter),"Visit"}}),
                transformedNames  = Table.TransformColumnNames(renamedColumn,
                    each if (_ <> "ID") then (quarter & " " & _) else _
                ),
                transformedNames1 = Table.TransformColumnNames(transformedNames, each
                    List.Accumulate(textToRemove, _, (state,current)=> Text.Replace(state,current,""))
                ),
                columnNames1 = Table.ColumnNames(transformedNames1),
                replacedNulls = Table.ReplaceValue(transformedNames1,null,0,Replacer.ReplaceValue,columnNames1)
            in
                Table.UnpivotOtherColumns(replacedNulls, {"ID"}, "Attribute", "Value"), type table
        }
    ),
    Combined = Table.Combine(Tranformed[GRP_Quarter]),
    PivotedColumn = Table.Pivot(Combined, List.Distinct(Combined[Attribute]), "Attribute", "Value"),
    targetColumns = List.RemoveItems(Table.ColumnNames(PivotedColumn),{"ID"}),
    ReplacedZero = Table.ReplaceValue(PivotedColumn,0,null,Replacer.ReplaceValue,targetColumns),
    ReorderedColumns = Table.SelectColumns(ReplacedZero,outColumnOrder,MissingField.Ignore)
in
    ReorderedColumns

Corresponding workbook avail. here

Cheers | Lz. (GMT +1)

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Answer
Answer

This is a perfect candidate for a PivotTable.

.

Actually, I would "back you data a step" to the "raw" data

.

Starting with raw data that looks something like this

Image

Although I wonder if the "Q visit" and count are redundant.  I'm guessing that "Visits based on hours" is a flag saying you have to do one or more visits during the Quarter, so the "Q Visit" column is redundant. And you might want to add a visit date column(?).

.

So, as you do a visit (with a date column), you enter the information. In that case, the "Count store Visits" column is also redundant.

.

Regardless, the information in the visit table is sent to a pivot table that can look something like this:

Image

I think it has summarized all of the information you are looking for ( ... I think ...)

Formatting color can be tweaked to provide alternating color bars and columns (by quarter) to make it easier to read.

.

This PivotTable is done without a single formula to debug.

.

PivotTables seem intimidating, but investing a few hours to learn the basics, you could create this table and go from there.

.

If you are interested in learning more about PivotTables, let me know and I'll provide you with links to some learning resources that got me started.

.

Here is the example workbook

https://1drv.ms/x/s!Am8lVyUzjKfpoXXCsYBhi6fdVXkC?e=RzeLzc

.
*****
.
As computer scientists we are trained to communicate with the dumbest things in the world – computers –
so you’d think we’d be able to communicate quite well with people.
Prof. Doug Fisher

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 13, 2025 Views 6,917 Applies to: