Database Folder Formulas with if statement and select property

I am new to Obsidian, and am not a programmer. I am migrating from Notion, where I had figured out how to create formulas with if() statements. I am trying to recreate this in Obsidian, but cannot find a tutorial on how to write formulas in that plugin. The documentation on Github is very minimal and seems to assume coding knowledge. Could someone please point me to where I can learn to format these formulas? The if() statement needs to evaluate the value of a select property on the same row. This is my last attempt before I go back to Notion…it seems Obsidian only works well for programmers (all the tutorials on YouTube are created by people who seem to know js…). Thank you in advance for your help!

Can you try to explain a bit more what you need the if statements for? The solution might be specific to your needs. You might want to take a look into dataview as a precursor to db folder since db folder is essentially a limited dynamic dataview.

Just for example, here you might have many different templates which contain dataview lists/tables/calendar queries which are quite simple to learn. DB folder is also quite new in development, so it might feel a bit bare coming from Notion. Give this plugin some time and explore other options as well.

Off the top of my head, the choice function for dataview is an if statement choice(boolean, if true, if false) and this can be used in dataview queries, which can be made exceptionally custom to pretty much any need you could need. Let us know what you need and I’m confident someone can help you!

Thank you for your reply! I am a musical engraver and want to keep track of my projects and billing in Obsidian. Each note has YAML properties such as source_format, delivery_format, and no_of_pages (and many more). The source_format field selects from 3 different options (“pdf” “finale” “dorico”). Each of these options means a different price per page, so I would like db folder to calculate the total cost according to the source_format selected like this:
if source_format = dorico, cost = 7 * no_of_pages
if source_format = finale, cost = 9 * no_of_pages
if source_format = pdf, cost = 11 8 no_of_pages
This is a simplification of the actual calculations, as many other factors go into the cost, but if I can figure out the syntax for this, I can probably figure out the other calculations.
Thanks in advance!

I haven’t had time to check out DB Folder in depth, but I know what you’re looking for is a db formula, either using js or maybe the dataview exposed function with the choice function. Although I can’t help you implement it, this is where I’d look.

Alternatively, you can add an inline-field:: (dataview plugin) to calculate cost as you described, then display it in your db folder without needing to go the formula route:

cost:: = choice(this.source_format = "dorico", 7*this.no_of_pages, choice(this.source_format = "finale", 9*this.no_of_pages, 11*no_of_pages))

then just make a new column in your db folder for this inline field. The calculation will instead be done in the note itself, and displayed in the db folder, as apposed to calculated in the db folder.

Edit: missing )

This sounds like the solution! I will try it soon. Thank you for spending the time explaining it.

That is at best imprecise. When you do a line like:

cost:: `= choice(this.source_format = "dorico", "if-true", "if-false" `

It feels like you’re setting cost to the value of that query, but in fact you’re setting the field to be the query. This means that if you display this field in the right circumstances it’ll do the calculations at that place in that context. In some cases, this might turn out to be what you want it to be, and in some it won’t work that way. So this is at best sketchy advice, which needs to be carefully tested in your various queries.

As proof I inserted the following field definition into three files:

greeting:: `=`

TABLE greeting, test
FLATTEN substring(greeting, 1) as test
WHERE file.folder = this.file.folder

`$= console.log("greeting has the value: ", dv.current().greeting)`

And the output in one of the files where:

And in the console I could read:

Sadly, I’ve not used database folder myself, so I can’t give you the proper advice on how to do formulas within database folder. If we talked about Dataview that would be a different matter, but then again that’s a different beast than database folder targeting other stuff.

But be patient, and hopefully someone will come along and give you proper advice using that plugin.

In the case you’re talking about you could do something like the following within that note:

TABLE WITHOUT ID costMultiplier * no_of_pages
  choice(source_format = "dorico", 7,
    choice(source_format = "finale", 9,
      choice(source_format = "pdf", 11, -1))) as costMultiplier
WHERE file.path = this.file.path

Another version of the same could be

TABLE WITHOUT ID altCostMultiplier * no_of_pages
    "dorico": 7,
    "finale": 9,
    "pdf": 11
  }[source_format] as altCostMultiplier
WHERE file.path = this.file.path

Similar queries could be used across folders (or the vault), and do calculations related to each file. One would then change the WHERE clause to no limit itself to the current file.

Yes, you’re right, I was under the impression it would render in the table, I thought it had worked for me before so I didn’t test my reply.

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