Replace metadatas by pictogram in my dataview table?

Hi there!

I’m new to obsidian, and code actually, and I wanted to tweak my dataview table a little bit.
In the metadatas of my notes I have “status:”. So far I have 4 status possibles for my notes.
In the dataview table, I would like those status to be replace by a pictogram/emoji.

I have trouble setting “conditions” to the replace() expression
I tried using IF() and CASE WHEN but it doesn’t work.

Maybe I’m not doing it right. Or maybe I need to stick with manually choosing the pictogram/emoji within the metadatas and it’ll show in my table.

It’s not capital but I was intrigued to see if it was possible!
What do you think?

take a look at the choice() function, that should help you:
https://blacksmithgu.github.io/obsidian-dataview/reference/functions/#choicebool-left-right

What kind of values does status have? Textual? Single character?

In any case, given that it’s only going to be four different values, you could also try the following:

FLATTEN {
  "A": "Icon for A",
  "B": "Icon for B",
  "C": "Icon for C",
  "D": "Icon for D" }[status] as statusIcon

Then you’d use statusIcon instead of status in the column setup. The FLATTEN should go somewhere in between your TABLE/FROM and the WHERE/GROUP/SORT clauses. If you get any issues, please show us more of your query.

Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like for code blocks or queries) is properly shown.

It works! I wasn’t familiar with the flatten expression :+1:
Thanks Holroy!

1 Like

Interesting! I’ll go with the “flatten” one for this but I definitively keep the choice function in mind for future needs.
Thanks!

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