I am setting up new Daily Notes with inline fields to record meals,
Example: FoodLog:: 2:00 AM - Lunch - Salad
My query returns a result for all FoodLog entries.
Query
TABLE
split(FoodLog, “-”)[0] AS “Time”,
split(FoodLog, “-”)[1] AS “Meal”,
split(FoodLog, “-”)[2] AS “Food”
FROM “0-Inbox”
WHERE contains(FoodLog, “”)
flatten FoodLog
SORT file.name desc
Result
The problem… how do i filter for just one type of meal… i.e. Dinner
I have tried (see below) but it does not work and don’t understand why.
TABLE
split(FoodLog, “-”)[0] AS “Time”,
split(FoodLog, “-”)[1] AS “Meal”,
split(FoodLog, “-”)[2] AS “Food”
FROM “0-Inbox”
WHERE split(FoodLog, “-”)[1] = “Dinner”
flatten FoodLog
SORT file.name desc
Taking your query as start point, you have two issues:
the WHERE split(FoodLog, "-")[1] = "Dinner" should be placed in the line AFTER the flatten command, not before;
when you use split(FoodLog, "-")[1] or similar you need to pay attention to the usual ignored spaces - if in the expression “2:00 AM - Lunch - Salad” you split by “-”, then you leave the ignored spaces as parts of the new strings (for example, with split(FoodLog, "-")[1] in “2:00 AM - Lunch - Salad” the outputted string is " Lunch " with a space before and after).
To solve this you need to write the split code as split(FoodLog, " - ")[1]
Your final query:
TABLE
split(FoodLog, " - ")[0] AS "Time",
split(FoodLog, " - ")[1] AS "Meal",
split(FoodLog, " - ")[2] AS "Food"
FROM "0-Inbox"
WHERE FoodLog
FLATTEN FoodLog
WHERE split(FoodLog, " - ")[1] = "Dinner"
SORT file.name desc
That works!!
Thanks so much for this.
I have a background using SQL, I have to learn about the command sequence in Dataview. Multiple where clause is a bit strange, but love Dataview.