The documentation for the "sorts" field in a query does not explain what "desc 0" means. In https://developers.looker.com/api/explorer/4.0/methods/Query/run_inline_query?sdk=py the example it gives shows:
{
...,
"sorts":["products.count desc 0"],
...
}
but the documentation makes no mention of it
Sorting for the query results. Use the format ["view.field",...] to
sort on fields in ascending order. Use the format ["view.field desc",...]
to sort on fields in descending order. Use ["__UNSORTED__"] to disable
sorting entirely. Empty sorts [] will trigger a default sort.
What does the 0 indicate? I tried seeing what various values might do but they seem to get ignored, e.g. -1, 1, 5000, sdfdfsfsdfs, etc. I also see examples of "desc 0" used in other areas of Looker documentation.
Solved! Go to Solution.
Hello John,
I've replicated it internally using API explore in my instance for a query, and below are the findings:
By default, if we don't specify any number after "desc" in "sorts," it's acceptable if we don't want to sort out the measure in question with the pivoted dimension. The integer after "desc" in the "sorts" field specifies a pivot column. Therefore, if the field being sorted is a measure, the integer refers to the pivot index of the column.
Here's a snippet to better visualize the explanation above:
If I don't include any number after `desc` in the API request:
It gets sorted on column 1 by default (without any number).
If I use `desc 0` and run, the output remains the same as it continues to sort on the 1st column.
Once I change it to `desc 1`:
It sorts based on the 2nd column.
Once I change it to `desc 2`:
It still sorts based on the 2nd column.
I hope this explanation helps!
Respectfully,
Mukul
Hello John,
I've replicated it internally using API explore in my instance for a query, and below are the findings:
By default, if we don't specify any number after "desc" in "sorts," it's acceptable if we don't want to sort out the measure in question with the pivoted dimension. The integer after "desc" in the "sorts" field specifies a pivot column. Therefore, if the field being sorted is a measure, the integer refers to the pivot index of the column.
Here's a snippet to better visualize the explanation above:
If I don't include any number after `desc` in the API request:
It gets sorted on column 1 by default (without any number).
If I use `desc 0` and run, the output remains the same as it continues to sort on the 1st column.
Once I change it to `desc 1`:
It sorts based on the 2nd column.
Once I change it to `desc 2`:
It still sorts based on the 2nd column.
I hope this explanation helps!
Respectfully,
Mukul