Dataview to Inline DataviewJS

Hello forum,

How can I get this dataview code:

	length(rows) AS Total
where objekttype = "Aktion" AND projekt = this.projekt

in Inline DataviewJS, so that I can set the occurrence in a line?

Things I have tried

`$= dv.pages().where(p => p.objekttype === "Aktion" && p.projekt === this.projekt).length`

gives back only 0
How doi I set the Group by correctly?

Do you really need to do equivalent of group by true? If you’re just counting it, you should be good just doing the length of your original result set.

However, we’re here to your aid, and there are two things which needs to happen. The first is vital, and the second might be unnecessary (as suggested above).

In dataviewjs you can’t use this, you need to use dv.current() instead. The group by clause is usually written like: .groupBy( p => to group on the file name, but in your case I reckon you could use something like .groupBy(p => true).

I’m not coherent tonight, so maybe the following would work:

`$= dv.pages().where( p => p.objekttype === "Aktion" && p.projekt === dv.current().projekt).length `

Or with the group by statement, and doing the length on the rows (still untested):

`$= dv.pages().where( p => p.objekttype === "Aktion" && p.projekt === dv.current().projekt).groupBy(p => true).map(p => p.rows.length) `

Hopefully either of these alternatives (or both if I’m extremely lucky, which I usually ain’t), should work for you!

Thanks holroy,

well, i just set in another property to test it out.

$= dv.pages().where( p => p.objekttype === "Aktion" && p.projekt === dv.current().projekt).groupBy(p => p.sektion).map(p => p.rows.length)

<empty list>

What I try to achieve is:
to count the occurrency of the sektion in inline DVJS like it comes out of this DV query:

	length(rows.key) AS Total
where objekttype = "Aktion" AND projekt = this.projekt  
GROUP BY sektion

what results this:


but i just want it inline as a number,
let’s say like this:
“there are 8 different occurrencies”

or respectively, because actually there are only 7 (1 occ. is given out as “-”.

So, as usual, I let count frequencies of the grouped elements.
(above example column “Total”), but here I only want to count the groups themselves.

btw. Have a nice holiday!

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