PIVOTBY Table with custom sorting

tana

Board Regular
Joined
Jan 22, 2021
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hi, does anyone know if there is way to custom sort the row of table made by PIVOTBY? Thanks,
 
Hello, generally speaking you could e.g. wrap PIVOTBY into SORTBY where by_array argument would refer to a range or an array containing the desired custom order or use a helper column with custom sorting and select it as part of row_fields argument.
 
Upvote 0
Hello, generally speaking you could e.g. wrap PIVOTBY into SORTBY where by_array argument would refer to a range or an array containing the desired custom order or use a helper column with custom sorting and select it as part of row_fields argument.
I have the following table

1740941721596.png


I would like to sort the rows as the following sorted order except Total row

1740941776730.png

Is it possible? Thanks,
 
Upvote 0
Many thanks for posting the example. I presume that you have source data somewhere from which PIVOTBY calculates the outcome. Instead of using the row_fields range as you have it now (your current row_fields range), try to replace it with the following: REPT(UNICHAR(8203),XLOOKUP(your current row_fields range,your current custom order list,SEQUENCE(ROWS(your current custom order list),,ROWS(your current custom order list),-1)))&your current row_fields range. By "your current custom order list" I mean the list in the table 2 above. I.e. something like:

Excel Formula:
REPT(UNICHAR(8203),XLOOKUP(A2:A1000,E1:E10,SEQUENCE(ROWS(E1:E10),,ROWS(E1:E10),-1)))&A2:A1000
 
Upvote 0
Many thanks for posting the example. I presume that you have source data somewhere from which PIVOTBY calculates the outcome. Instead of using the row_fields range as you have it now (your current row_fields range), try to replace it with the following: REPT(UNICHAR(8203),XLOOKUP(your current row_fields range,your current custom order list,SEQUENCE(ROWS(your current custom order list),,ROWS(your current custom order list),-1)))&your current row_fields range. By "your current custom order list" I mean the list in the table 2 above. I.e. something like:

Excel Formula:
REPT(UNICHAR(8203),XLOOKUP(A2:A1000,E1:E10,SEQUENCE(ROWS(E1:E10),,ROWS(E1:E10),-1)))&A2:A1000
Thanks for your help, Sofia.

I think I found the solution for now. Since I am not that familiar with REPT & UNICHAR functions. I end up using LET statement & XMATCH to retrieve the index order.

Appreciate for all your help!!!
 
Upvote 0

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