Dataview query filtering inline field content

Things I have tried

What I’m trying to do

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
image

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

Thanks in advance for any help.
RobMac58

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
2 Likes

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.

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