What is "desc 0" in Sorts?

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 Solved
0 1 468
1 ACCEPTED 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:

mukulmunjal164_9-1709967776891.png

If I don't include any number after `desc` in the API request:

mukulmunjal164_10-1709967802855.png

 

It gets sorted on column 1 by default (without any number).

mukulmunjal164_11-1709967814991.png

 

If I use `desc 0` and run, the output remains the same as it continues to sort on the 1st column.

mukulmunjal164_12-1709967833445.png

 

mukulmunjal164_13-1709967846748.png

 


Once I change it to `desc 1`:

mukulmunjal164_14-1709967860302.png

 

It sorts based on the 2nd column.

mukulmunjal164_15-1709967874902.png

 

Once I change it to `desc 2`:

mukulmunjal164_16-1709967892124.png

 

It still sorts based on the 2nd column.

mukulmunjal164_17-1709967904441.png

 I hope this explanation helps!

Respectfully,
Mukul

View solution in original post

1 REPLY 1

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:

mukulmunjal164_9-1709967776891.png

If I don't include any number after `desc` in the API request:

mukulmunjal164_10-1709967802855.png

 

It gets sorted on column 1 by default (without any number).

mukulmunjal164_11-1709967814991.png

 

If I use `desc 0` and run, the output remains the same as it continues to sort on the 1st column.

mukulmunjal164_12-1709967833445.png

 

mukulmunjal164_13-1709967846748.png

 


Once I change it to `desc 1`:

mukulmunjal164_14-1709967860302.png

 

It sorts based on the 2nd column.

mukulmunjal164_15-1709967874902.png

 

Once I change it to `desc 2`:

mukulmunjal164_16-1709967892124.png

 

It still sorts based on the 2nd column.

mukulmunjal164_17-1709967904441.png

 I hope this explanation helps!

Respectfully,
Mukul