# Power Query Sort Ascending, Null Last



## cr731 (Sep 28, 2018)

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.


----------



## Guenther45 (Sep 29, 2018)

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


----------



## Ozeroth (Sep 29, 2018)

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:

```
= Table.Sort(PreviousStep, each if [Date] = null then #date(9999,1,1) else [Date])
```

Regards,
Owen


----------

