Dataview - Counting Instances of Emoji's From Inline Fields

Greetings All,

I have started using Dataview over the last week or so am seem to have reached a bit of a hurdle. I should note here I have some coding experience but not specifically with JS so i’ve been sticking to the DQL for now.

I am presently looking to create a daily note, in a sense a journal (though this isn’t relevant to the technical side the context may help), which I will complete each day.

Each of the notes presently are tagged with #journal

Presently I have an Inline Field called thoughts:: to which I am adding emojis as responses such as :office: or :baby_bottle: (however if needed these could be swapped out for words such as ‘office’ or ‘baby’)

An example line would be thoughts:: 🏢🍼

What I’m trying to do

I am looking to create a table which counts the instances of each of the emojis across the notes tagged "#journal’ so that is would look something like this;

Emoji | Count
:office: | 3
:baby_bottle: | 2

The problem comes when there is more than one Emoji used in Inline Field, as such I have detailed the below to hopefully explained further;

  • When only ONE emoji is in the Inline Field, the table shows the count;

thoughts:: 🏢

Emoji | Count
:office: | 1

  • When TWO OR MORE emojis are in the Inline Field, the table shows nothing;

Emojis | Count

Things I have tried

I have used a combination of different TABLE attempts, some of which I don’t have to hand now but the latest I have is the following;

TABLE 
length(rows) as Count
WHERE type = "journal"
WHERE thoughts = "🏢" or thoughts = "🍼" or thoughts = "♻" or thoughts = "🩺" or thoughts = "📺" or thoughts = "💔" or thoughts = "💝"
GROUP BY thoughts

I have also tried to add the thoughts:: section into the YAML Frontmatter in case that worked but that didn’t seem to be picked up by the table either.

I have routed around the forums (both here and reddit) and also the Dataview docs, I think this might be me incorrectly using Inline Fields, but this could just be me being a melon.

Thanks in advance peeps

In theory what you would need to do is to split thoughts up into it separate characters, and then count each character. But just now I’m not sure how to split reliably on emoji characters (which often are multibyte characters). Especially if we need to be within the DQL query context.

If you could add a separator it would be easier, as you then could split on that character, so maybe that’s the way forward? Using something simple as a space would make this a whole lot easier to work with.

If you had them separate by space, then something like the following should get you a little bit closer to your goal:

```dataview
TABLE length(rows) as Count
WHERE type = "journal"
  AND thoughts
FLATTEN split(thoughts, " ") as thought
GROUP BY thought
```

Update: The following Stack Overflow showcases how hard it is to split on emoji’s and other characters: javascript - How can I split a string containing emoji into an array? - Stack Overflow

1 Like

Another case would be if you added multiple of those inline fields in your notes. Then you could have thoughts become an array. Is that likely to happen, or are you sure you just add one thoughts inline field per note?

Put another way, if you have multiple thoughts you get an array of thoughts, where each element could have multiple emojis. That would break my script as it stands. If you switch around though, and demand that every emoji has its own inline field, you could just split that array into its separate emojis…

Does that make sense? Do you see the difference in those definitions?

Hi @holroy

The first solution with the code block did just what I needed it to and it does seem to be working with emoji’s, that being said if it has any issues I will switch to text as that works also.

Honestly thank you so much for your help here

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