Dataview: Replace number with emoji from array?

Dear Forum,

I try already an hour to make this work but without any progress :frowning: I want to replace a rating number (1-5) with its corresponding emoji in a dataview query. I tried the following (getting the corresponding emoji from an array by using the rating number as index), which doesn’t work. Any idea how this can be achieved?

dataview
Table aliases as Summary, ['😭','😪','😐','😊','😎'][rating] as Rating
FROM "Journal"

Cheers, H.

Someone might be able to give you the native method for this, but I usually find these things easier using dataviewjs rather than dataview:

```dataviewjs
dv.table(['Link', 'Rating'], dv.pages('"Journal"')
  .where(page => page.rating)
  .map(page => [page.file.link, ['😭','😪','😐','😊','😎'][page.rating - 1]]))
```

Note that I have asked for only pages that include a rating (the .where line), and that would exclude any entry that has a rating of zero. You might need to adjust.

(I have tested the above and it functions perfectly.)

Thank you Alan, I will give it a try!

There’s Choice to the rescue :slight_smile: Choice(boolean, true, false) can be nested.

…dataview
TABLE aliases as Summary, choice(rating=0, :sob:, choice(rating=1, :cry:, choice(rating=2, :expressionless:, choice(rating=3, :smiling_face:, choice(rating=4, :sunglasses:, :question:))))) as Rating
FROM Journal

Do count the closing brackets, please. I always miscount.

Sorry for the … instead of ```, the emojis won’t render otherwise.

Thank you Ria for the idea with the nested choices, I’ll give it a try! Cheers, H.

Another option is to create the list of emojis and select the n’th element, like in the following:

rating:: 3
```dataview 
TABLE rating, list("dummy", "a", "b", "c")[rating] as Emoji
WHERE file = this.file 
```

Should be easily adapted to your use case.