Sorting nulls last

Hi. Is there a way to sort a column in a table in descending order with nulls last instead of first? The default behavior (nulls appear at the top) is most painful in merged results where a coalesce on LookML level is not possible. I can imagine that in a vast majority of cases nulls actually mean 0 and this seems like such a basic functionality that I wonder if I am not missing some obvious solution…

Solved Solved
1 17 3,140
1 ACCEPTED SOLUTION

Hi @Prasham_Ashesh

I actually haven’t gotten to try it yet… but my first stab at it would be something like:

measure: foo {
  ...
  order_by_field: foo_nulls_last
}

measure: foo_nulls_last {
 type: <depends on type of foo, either number or string>
 sql: CASE WHEN ${foo} is NULL THEN <value that sorts last> ELSE ${foo} END ;;
}

View solution in original post

17 REPLIES 17
Top Labels in this Space