# Ascending and descending in the context of the order of operations on Datasets

I did not understand the concepts ascending and descending in the context of the order of operations on Datasets. It is listed in the documentation, on Dataset's page and yet I did not understand. Perhaps a reference to a place that has a more detailed explanation of this topic will suffice. Thanks.

• From the documentation "A descending operator is applied to corresponding parts of the original dataset, before subsequent operators are applied at deeper levels." So ascending an descending operators behavior depends on the order, the sequence in which the operators are involved. Apr 7 '20 at 16:42
• also see Struggling to understand Query Apr 8 '20 at 1:39
• Thank you WReach!!! your comment was very important for me
– Dani
Apr 14 '20 at 15:40

I'll bite. Let's play with the "Planets" dataset, as it offers a great example of nesting.

planets = ExampleData[{"Dataset", "Planets"}]


# Descending operators

Part operators such as All and "key" are descending operators, which means that the next operator will be applied at a nested level. Compare:

planets[Length]
(* 8 *)


as we have 8 rows in our dataset. Length here is applied to the whole dataset.

In the next expression, All descends one level down, so now Length is applied individually to each row. Since every row of the above dataset is an association with three keys - Mass, Radius, and Moons, the result is 3 for every row:

planets[All, Length]


Let's keep descending. In the next expression, "Moons" descends one more level, into the list of individual planets, so now Length operates at this level and returns the number of moons per planet:

planets[All,"Moons",Length]


# Ascending operators

Any function, such as Length above, is ascending, which means that it does not descend and operates at the current level. However, one other important feature is that an ascending operator is applied after all subsequent ascending and descending operators have been applied to deeper levels.

Consider the difference between

planet[All,"Moons",Total]


which aggregates every parameter in Moon column with Total,

versus

planet[All, "Moons", Total, "Mass"]


Here, Total is applied after the following "Mass" descending operator selects just that column.

• This brings me closer to understanding the distinction (+upvote). Apr 7 '20 at 18:50
• Thank you for the compliment, Daniel, that means a lot coming from you! Apr 7 '20 at 21:10