Deneb - Changing Sort Order

Hello,
sorry I am back again on the same report, but starting a new thread as the question is completely different.
I was asked to change the sort order for the categories. Now I have to admit I have been playing around trying to do it, but I can’t understand where to put this information…
the template from Daniel has a sort based on row number (how are these determined by DENEB?) and a sort based on the sum of a measure.

I don’t know which one I have to change and how… I am also puzzled as the y sort done on
“op”: “sum”,
“field”: “Spending YTD”,
“order”: “descending”

only seems to work in “descending”, if I try to change it to “ascending” then I get the error message:
Domains that should be unioned has conflicting sort properties. Sort will be set to true.

Can you please help me understand?

Thanks a lot!
Kind regards
Valeria

ex. DENEB ShowCase question Sort Order.pbix (1.3 MB)

Hi @valeriabreveglieri.

I think using the Vega-Lite fold transform is the issue; in the “second” application the “first” field does not exist, so can’t be used for the sort. Here’s an alternative that uses layers instead of the fold transform.

What I did:
• deleted the fold transform
• moved the Y-encoding outside the layer block (so it can now be shared amoung the layers)
• deleted the “size”, “order”, and “color” blocks from the encoding for the bar mark
• added a “color” for the bar mark
• added a “height” for the bar mark
• duplicated the bark mark (forecast and spending 1st [so in background], spending ytd above)
• duplicated the text mark

My solution to Deneb Workout #5 may be useful as a reference.

Hope this helps.
Greg
eDNA Forum - Deneb Sort Order.pbix (1.3 MB)

2 Likes

Hi @Greg,
THANKS!!! Clear and working :slight_smile: .
To follow-up, I really wanted the sort order to be by the field “SortOrder” which in this case happens to be the same as the ascending YTD Actual, but in other cases is not, and users don’t want to see the category shift every time - this is why they asked to “anchor” it with a static order.
Now, I tried to change my numbers not to make the SortOrder correspond to sum of the ascending YTD Actuals and I have re-attached the file…
what I can’t understand is why, to make it work, I still have to use an “op” in my sort (in the y encoding channel). And by he way the “op” type does not seem to change things (whether I use sum, average,…)

  "sort": {
    "op": "sum",
    "field": "SortOrder",
    "order": "ascending"
  }

Otherwise I get the error:
[Warn] Domains that should be unioned has conflicting sort properties. Sort will be set to true.
and the sort is not preserved any longer.

eDNA Forum - Deneb Sort Order.pbix (1.3 MB)

I feel like I am missing something here…

Thanks again!!!
Kind regards
Valeria

Hi @valeriabreveglieri

AFAIK, there are 3 required key-value pairs to define sorting by another field in Vega-Lite:

  • op (the aggregate operation to perform on the field prior to sorting)
  • field (the data field to sort by)
  • order (the sort order [ascending; descending; null])

When you have a single value, all the aggregations will be the same (e.g., sum, avg, min, max, count, mean, median, etc.).

I tried your uploaded file and didn’t see any problembs ysing the [SortOrder] field; AFAIS (saw), sorting worked as intended and I didn’t see anything wrong. I also don’t know where you saw the warning and couldn’t reproduce it.

In any event, for more information, here’s the write-up on the Vega-Lite website.

Greg

2 Likes

Hello Greg!
Yes you perfectly answered my question :slight_smile: The error I had was when I removed the “op” - and just kept “field” and “order”. If you do so, then the error appears and the sort is just set to true.
I was also puzzled by the fact that, if I kept the “op” and changed the aggregation type (sum vs. min vs. average etc) , nothing actually changed - but you addressed that, so it’s actually normal when there is a single value.

So thanks a lot - it’s much clearer now!
Kind regards
Valeria

1 Like