Condensed table with one line per chosen properties (i.e. a "shopping list" based on individual "recipes" with "ingredients" as properties (using dataview))

What I’m trying to do & Things I have tried

I have a set of notes, each of which has items I need to collect, and the quantity to collect. Not actually a recipe, but similar to it, and easier to explain that way.

Let’s say the items I need to collect are eggs and milk.

My note for pancakes might be;

---
eggs: 2, fresh, room temperature
milk: 1 cup
---

A separate note for mufins might be:

---
milk: 1 cup
---

I can get a list of all the recipes that call for eggs and how many they need fairly easily. Using this:

TABLE WITHOUT ID
"eggs" as NAME, file.link AS "RECIPE", "text", eggs as "QUANTITY"
FROM "This week's recipes"
WHERE eggs

I get something like:

NAME RECIPE “text” QUANTITY
eggs pancakes “text” 2, fresh, room temperature

[!unrelated]-
(unrelated issue: the quotations around text seem to show up, which is not what I expected,
and in fact, I would like the “text” column to be blank. These are separate issues)

Likewise for milk:

NAME RECIPE “text” QUANTITY
milk pancakes “text” 1 cup
milk muffins “text” 1 cup

Some recipes don’t have milk, some have other ingredients, and most have properties unrelated to either of these, that I do not want to appear.

What I want is this:

NAME RECIPE text QUANTITY
eggs pancakes 2, fresh, room temperature
milk pancakes 1 cup
milk muffins 1 cup

One table, that lists all the ingredients/qtys I need to gather, and only that.

Is there any way to do this? I know I could do something like this (my syntax may be off):

TABLE WITHOUT ID
"eggs" as NAME, file.link AS "RECIPE", "text", eggs as "# Eggs", milk as "# Milk"
FROM "This week's recipes"
WHERE eggs or milk

but that would create multiple columns, and only one line per file, I think. I want one line per occurrence of each of the chosen properties, even if they are from the same file.

I have searched for recipes, but the ones I found used different setups (tags, not properties, not dataview, etc.)

You’re making it very hard for yourself when only some of the properties are to be treated as ingredients (or as interesting for the shopping list). You would be better suited if you actually made a dedicated list of either properties, or inline fields holding your interesting items.

Here are two working examples with a better structure:

---
Tags: f92768
ingredients:
- name: eggs
  quantity: 2
  text: fresh, room temperature
- name: milk
  quantity: 1 cup
---
questionUrl:: http://forum.obsidian.md/t//92768

## Using compound properties

```dataview
TABLE WITHOUT ID I.name as Name, I.quantity as Quantity, I.text as Text
WHERE file.folder = this.file.folder
FLATTEN ingredients as I
```

## Using lists

- (quantity:: 2) (name:: eggs) - (text:: Fresh, room temperature)
- (quantity:: 1 cup) (name:: milk) 

```dataview
TABLE WITHOUT ID item.name as Name, item.quantity as Quantity, item.text as Text
WHERE file.folder = this.file.folder
FLATTEN file.lists as item
WHERE item.name
```

The displayed output is:

In the output I produce just the local file’s ingredients or shopping list, but this can easily be extended to also include the file name as the recipe name or similar.


If you insist on keeping the structure you have, you need to find some way to determine which property are part of the recipe or not. Or potentially, to declare all the properties from another list not to be part of the recipe.

And then start massaging the entire list of properties. I’m not going to write the query as of now, as a change in structure would be the better option.

1 Like

Very well thought out solution. I did notice one thing. In the Using lists example, item.text is an existing property, so you get ALL the text contained in the item. If you rename the inline field to something different, like notes, then the behavior matches your Using compound properties example.

## Using lists

- (quantity:: 2) (name:: eggs) - (notes:: Fresh, room temperature)
- (quantity:: 1 cup) (name:: milk) 

```dataview
TABLE WITHOUT ID item.name as Name, item.quantity as Quantity, item.notes as Notes
WHERE file.folder = this.file.folder
FLATTEN file.lists as item
WHERE item.name
```

You could try something like " " AS "text"

```dataview
TABLE WITHOUT ID
"eggs" as NAME, file.link AS "RECIPE", "  " AS "text", eggs as "QUANTITY"
FROM "This week's recipes"
WHERE eggs
```

Are you using this for spacing? If so, another way might be to use some HTML. You could remove the “text” column and modify the “RECIPE” using a <span> with some padding…

```dataview
TABLE WITHOUT ID
"eggs" as NAME, file.link as "<span style='padding-right:2em;'>RECIPE</span>", eggs as "QUANTITY"
FROM "This week's recipes"
WHERE eggs
```

Thank you so much. Those are great ideas. I realize my data structure is not standard, but it is very simple to input, which is also a goal. My ultimate question was if it was possible to join everything into one column. I like your solution regarding lists and I am going to think it through, as it means recomposing a bunch of files. But I can see where it would work for a certain style.

You could try something like " " AS "text"

Yes, I realized that the next day. Dataview scares me. The documentation is written for people who already know the answer, so I keep looking for the simplest structure possible. I can work my way through examples, but I can’t quite think in it yet.

1 Like

Nothing wrong with that. A solution is a solution, and life is a journey. I’m learning something new everyday with the help of people like @holroy who go above and beyond to help us in the community.

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