# Sort Dataview Grouped Elements by number of appending rows

**URL:** <https://forum.obsidian.md/t/sort-dataview-grouped-elements-by-number-of-appending-rows/80578>\
**Category:** Help\
**Tags:** dataview\
**Created:** [April 19, 2024, 10:42am UTC](https://forum.obsidian.md/t/sort-dataview-grouped-elements-by-number-of-appending-rows/80578 "2024-04-19T10:42:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![toteZitrone](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/t/9de053/32.png) [@toteZitrone](https://forum.obsidian.md/u/toteZitrone)\
**Post date:** [April 19, 2024, 10:42am UTC](https://forum.obsidian.md/t/sort-dataview-grouped-elements-by-number-of-appending-rows/80578/1 "2024-04-19T10:42:16Z")

</div>

### What I’m trying to do

I have several cases where I retrieve a dataview table with grouped elements. In this case I let dataview display all “dead links” (for not-yet-existing notes) and also retrieve the array of notes that generate this link. (Code below)

What I would like to do now, is to sort the first row (which are the non-existing notes) depending on how many notes are linking to them in the second column, so that I can easily see, which notes are especially important to make.

```dataview
TABLE rows.file.link AS Bezug 
FLATTEN file.outlinks AS OUT
WHERE !OUT.file AND !(contains(meta(OUT).path, "/"))
GROUP BY OUT AS Anzulegen

```

### Things I have tried

I tried google/forum search and browsed the Dataview library, but couldn’t find helpful information whether this is possible. I think there might be an option to retrieve the number alue of the connected notes-array by JS (no?) but I do not know JS and am not sure this can be applied as a sorting method to the first main column.

---

<div class="post-metadata">

**Author:** ![toteZitrone](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/t/9de053/32.png) [@toteZitrone](https://forum.obsidian.md/u/toteZitrone)\
**Post date:** [April 19, 2024, 10:57am UTC](https://forum.obsidian.md/t/sort-dataview-grouped-elements-by-number-of-appending-rows/80578/2 "2024-04-19T10:57:25Z")

</div>

To clarify what I mean, here an (unordered) example table as retrieved by the dataview code:

| non existing note | files that link to it |
| --- | --- |
| note 1 | -a  
-b |
| note 2 | -c |
| note 3 | -a  
-c  
-y |

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [April 24, 2024, 7:36pm UTC](https://forum.obsidian.md/t/sort-dataview-grouped-elements-by-number-of-appending-rows/80578/3 "2024-04-24T19:36:29Z")

</div>

You could try the following:

````auto
```dataview
TABLE rows.file.link AS Bezug 
FLATTEN file.outlinks AS OUT
WHERE !OUT.file AND !(contains(meta(OUT).path, "/"))
GROUP BY OUT AS Anzulegen
SORT length(rows) desc, key
```

````

This should sort by the number in each group, and then by key if the number is equal.

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [July 23, 2024, 7:36pm UTC](https://forum.obsidian.md/t/sort-dataview-grouped-elements-by-number-of-appending-rows/80578/4 "2024-07-23T19:36:33Z")

</div>

Closed on July 23, 2024, 7:36pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
