SORTBY
Detailed Process Flow to Use the SORTBY Function in Excel
What is the SORTBY Function?
The SORTBY function in Excel sorts a range or array based on values in a corresponding range or array. Unlike the traditional SORT function, SORTBY allows sorting based on another column while keeping the original dataset intact.
Purpose of the SORTBY Function
- To sort data dynamically based on one or more columns.
- To avoid altering the original dataset while still organizing data efficiently.
- To apply multi-level sorting based on various criteria such as highest working days, department names, or employee codes.
Benefits of Using SORTBY Function
✅ Dynamic Sorting – When data updates, the sorting automatically adjusts.
✅ Maintains Original Data – Unlike manually sorting, this function keeps the raw dataset unchanged.
✅ Multi-Level Sorting – You can sort by multiple criteria (e.g., working days first, then department).
✅ Eliminates Manual Work – Reduces the need for frequent manual re-sorting.
Syntax of SORTBY Function =SORTBY(array, by_array1, [sort_order1], [by_array2], [sort_order2], …)
- array – The range of data to sort.
- by_array1 – The column by which sorting is done.
- sort_order1 – (Optional)
1
for ascending,-1
for descending. - by_array2 – (Optional) Additional column for secondary sorting.
- sort_order2 – (Optional) Sorting order for the second column.
Example 1: Sorting by "W. Days" in Descending Order
Formula: =SORTBY(A2:D26, D2:D26, -1)
Explanation:
A2:D26
→ Selects the range of employee data.D2:D26
→ Sorts based on W. Days.-1
→ Sorts in descending order (highest to lowest working days).
Example 2: Sorting by "Department" (A-Z) and then "W. Days" (Highest to Lowest)
Formula: =SORTBY(A2:D26, C2:C26, 1, D2:D26, -1)
Explanation:
C2:C26, 1
→ Sorts by Department in ascending order.D2:D26, -1
→ Within each department, sorts W. Days in descending order.
Sample Output for Example 2
Emp. Code | Name | Department | W. Days |
---|---|---|---|
48351 | Singh Bajetha | Machine A | 16 |
48765 | Ganesh Shankar | Machine A | 20 |
47117 | Ripu Kumar | Machine B | 21 |
49132 | Prakash Kumar | Machine B | 18 |
50030 | Amar Singh | Machine B | 18 |
47125 | Govind Ram | Machine C | 18 |
47565 | Sunil Chandra | Machine C | 18 |
47336 | Singh Bisht | Machine C | 20 |
48337 | Singh Mehta | Machine C | 21 |
48862 | Suresh Chandra | Machine C | 26 |
This ensures that employees are grouped by department while also arranging them in descending order of W. Days.
Conclusion
The SORTBY function in Excel is a powerful tool for dynamically sorting data without altering the original dataset. It is particularly useful in HR analytics, payroll management, and attendance tracking, where sorting based on multiple criteria is necessary. 🚀
Comments
Post a Comment