Dataview flatten from integer to icon

Hi All,

I have a bunch of files that have integer data for ratings between 0-5. I want to format it to a rating icon with stars. I found this interesting reply by @holroy (Replace metadatas by pictogram in my dataview table? - #3 by holroy) but not sure if it works with integers. Can someone help, please?

This is my query

TABLE WITHOUT ID "![coverimg|100](" + cover + ")" as Cover, link(file.link, title) AS Title, author AS Author, completed AS Read, ratingIcon as Rating
FROM "Books"
FLATTEN {0: "",1: "β˜…β˜†β˜†β˜†β˜†",2: "β˜…β˜…β˜†β˜†β˜†",3: "β˜…β˜…β˜…β˜†β˜†",4: "β˜…β˜…β˜…β˜…β˜†",5: "β˜…β˜…β˜…β˜…β˜…"}[rating] as ratingIcon
WHERE econtains(status, "read")

If it didn’t work like that, I reckon (without testing) it’ll work if you make the key a text:

```dataview 
TABLE WITHOUT ID "![coverimg|100](" + cover + ")" as Cover, link(file.link, title) AS Title, author AS Author, completed AS Read, ratingIcon as Rating
FROM "Books"
FLATTEN {"0": "","1": "β˜…β˜†β˜†β˜†β˜†","2": "β˜…β˜…β˜†β˜†β˜†","3": "β˜…β˜…β˜…β˜†β˜†","4": "β˜…β˜…β˜…β˜…β˜†","5:: "β˜…β˜…β˜…β˜…β˜…"}[rating] as ratingIcon
WHERE econtains(status, "read")
```
1 Like

Thank you @holroy for your quick reply. It’s sorted, I remember trying those quotes but maybe I had the FLATTEN pattern in the wrong place when I tried it I guess. Thanks again :+1:

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