Power Query Sort Ascending, Null Last

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
In Power Query, I have a column of date values that I want to sort ascending. In some cases, I have null values. I want null to be last, but Order.Ascending results in null values being at the top. Is there any good way to change this behavior? The only thing I can think of is to replace null with #date(9999,1,1), sort the column, then replace #date(9999,1,1) with null. If possible to avoid these steps, I’d like to.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hello,
maybe there is a simpler or better way, I just made it this way:
Table1 duplicated -> Table1 (2)
Table1 (2) filtered that only the null values ​​remain
Table1 filtered so that the null values ​​are removed
Table 1 sorted
Table 1 (2) attached

Regards
Guenther
 
Upvote 0
Hi there,
Another suggestion:
For the second argument of Table.Sort, you can provide a function that maps a row of the table (i.e. a record) to the value to be sorted. You can provide a function that maps nulls to #date(9999,1,1), otherwise leaves dates unchanged. Something like this:
Code:
= Table.Sort(PreviousStep, each if [Date] = null then #date(9999,1,1) else [Date])

Regards,
Owen
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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