I am wondering if there is a way in dataview to run a query that populates a table grouping frontmatter values by week/date (file.name) but calculating a numerical amount based on the emojis used in frontmatter… Basically I would like to have a query that calculates my weekly alcohol intake, which I save to frontmatter in Daily Notes as an emoji, i.e. or or or etc (or nothing at all ofc); but I want the query to actually tell me the numerical units of alcohol based on the total emojis used each day. For example:
= 2.5 units (so = 7.5 units) = 1.5 units (so = 3 units)
Things I have tried
Searched on the forum but couldn’t find what I need (I am a relatively new starter with Obsidian and dataview especially)
After a little testing, I discovered that doing split( ..., "") on the beer and wine glass indeed was multi-byte unicode characters, which makes the query a little more ugly. But the following seems to work for a simpler test case:
```dataview
TABLE WITHOUT ID drink, singleChar, units, sum(units)
WHERE file = this.file
FLATTEN drinks as drink
FLATTEN regexreplace(regexreplace(drink,
"🍺", "B"),
"🍷", "W")
as singleChar
FLATTEN list(map(split(singleChar, ""), (c) => object(
"B", 2.5, "W", 1.5)[c])) as units
SORT sum(units) DESC
```
Here we replace the multi-byte characters with a single byte character, singleChar. These characters are then mapped to a numeric value, and that list is stored into units, and then you could do sum(units) to calculate the total amount.