Changing Row Fields in pivot Table of Excel

Solution 1:

If you only ever want to use one row field at a time, you can stack the variables using PowerQuery.

Put your cursor in the data and use Data>Get & Transform Data>From Table/Range.

enter image description here

This will create a Table and open the PowerQuery Editor:

enter image description here

Select the Lower and Upper columns by holding down Ctrl and clicking on their headers and use Transform>Unpivot Columns. You should see this:

enter image description here

Rename the columns to something meaningful to you by right-clicking the column header and choosing Rename. You can also drag the columns to reposition them. I have renamed them and reordered as follows:

enter image description here

Now use Home>Close & Load to put the data back into the workbook.

You can create a pivot table from this dataset, putting the VariableMember on the rows, the Value in the Values and creating a slicer on Variable:

enter image description here

EDIT 1:

Here is another way that doesn't use VBA, DAX or PowerQuery, but does require that you refresh the pivot table after you select which column you want as a row header.

enter image description here

I have renamed cell G2 as selected_column. This is done by selecting a cell then entering a name into the Name Box, as described here. This is not strictly necessary, but I find it makes it easier to read formulas referring to this column.

I have converted the data range to a Table using Ctrl+T and added a column called 'Pivot row header' with this formula:

=IFS(selected_column="Lower",[@Lower],selected_column="Upper",[@Upper],TRUE,"")

This is just saying "If the value in cell G2 is Lower, then show the values from the Lower column in this column. If the value in cell G2 is Upper, then show the values from the Upper column in this column. Otherwise, show nothing in this column."

If you have more columns to select from, you can extend the IFS formula as many times as you like.

In cell G2, I have added data validation by using Data>Data Validation, and configuring the dialog like this:

enter image description here

So, my drop-down list in cell G2 shows the column headers from the first two columns in my Table, i.e. the values Lower and Upper.

When I select a value from this drop-down in G2, the values in column C in the table update.

I then need to refresh the pivot table to see the changes.

enter image description here