is there an elegant function that exists for the following problem?
I've been tasked to create a function to determine the differences in days and rank the values. The closest positive number would rank as 0 and be the 'starting point'. From the starting point, depending on whether the ranked value is negative, or non-negative, the function would assign a rank to the value either positive or negative respectively.
| Datediff() | Rank |
|---|---|
| -50 | -3 |
| -32 | -2 |
| -1 | -1 |
| 5 | 0 |
| 14 | 1 |
| 32 | 2 |
| 128 | 3 |
| 254 | 4 |
My solution so far would be to separate the negative and positive numbers and use the window.partitionBy() function to assign the correlating rank. It would work, but I'm curious for a more elegant solution. :)