Forum Discussion
Sorting on Grouped Column
- Anonymous4 years ago
This took me a few minutes now that I have some sample data to work with. It brute forces it (and by no means do I recommend this) but it maintains the column headers etc that you currently have:
1) Keep Year as a whole number
2)Create a custom column in the List table with the following code. This will make bins for you:
if [Year] <= 5 then "<5" else if [Year] >5 and [Year] <=10 then "6-10" else if [Year] >10 and [Year] <= 15 then "11-15" else if [Year] >15 and [Year] <=20 then "16-20" else "21-25"
3) Home Tab > Merge Queries
4) Merge List table and Sort Range Table using Bin in the List table, and Range in the Sort Range Table.
5) Expand table and select Sort Order:
6) close and apply
7) Sort by column now that you have the sort order in the table.
In Power Query, the Group year range is unavailable and the Merge function is grey out in Transformation menu. Thus, it is impossible to do unless I have missunderstand it.
The correct way would be to do it under the Home Tab to Merge Queries, but from the snippet you've sent I can see you don't have a uniquue idnetifier in the List table, you only have years so this isn't feasible.
Are you allowed to change the group names? If yes you could use the grouping function of columns which will create bins for you automatically and they are in the correct order (I typed it out based on your example):
- alvin1994 years agoHelper III
Hi again,
I ma allow to change the group name but it is great if it can be stated from x to y so the reader can know the limit of the range.
I am still stuck with the Merge part. I have created a new table called Sort Range. However, there are some issue as I am unable to click on OK button to proceed.
The issue is due to different data type. In Data View, both Year and Range are in Text data type.
However, the Year in Power Query become Whole number.
- Anonymous4 years agoNot applicable
When merging it needs to be on unique Identifiers which I only realised you don't have common unique ID's when I saw the snippet of the 2 tables you have.
However hopefully my answer before (involving creating a custom column) will help you achieve what you need.