Dataview Average using array values on a per-file basis

Hi all! I’m currently trying to implement a score system on some notes, and after searching a lot and trying some different things I’m stuck.

This is going to be used in a template where I want to display the Partial and Final Score in each file automatically.

My frontmatter currently looks like this:

`—
finalScore:

  • CVI: 18
  • INC: 32
  • COM: 20
  • ATC: 15
    —`

The idea is that in my note proper I’ll display a table with the 4 values and the final average score.

| CVI | 18 |
| INC | 32 |
| COM | 20 |
| ATC | 15 |
| Score | XX |

I’m currently unable to display either information. Is this setup possible?

Doing calculations against multiple fields requires you to specify which fields are meant to be calculated.

---
finalScore:
- CVI: 18
- INC: 32
- COM: 20
- ATC: 15
---

This syntax also says that finalScore is a list of the various items, so the full reference for COM would be this.finalScore[2].COM, since it’s the 3rd item in the list, and you want the COM part of this item.

If you change the syntax to something like the following:

---
finalScore:
- name: CVI
  value: 18
- name: INC
  value: 32
- name: COM
  value: 20
- name: ATC
  value: 15
---

Then you’d be able to do `= sum(this.finalScore.value) `, due to some inherent magic of dataview extracting the value field from each of the list items.

A proper compound object

Another way, which would be kind of nicer implementation of the compound object could be:

---
compoundScore:
  CVI: 18
  INC: 32
  COM: 20
  ATC: 15
---

Sadly, due to lack of the Object.keys( ... ) or equivalent within DQL queries, we’re then needing to go back to referencing the fields directly:

Sum: `= this.compoundScore.CVI + this.compoundScore.COM + this.compoundScore.INC + this.compoundScore.ATC `
My full test file

Here is the source of my full test file which I’m referring to in this answer:

---
Tags: f74265
finalScore:
- CVI: 18
- INC: 32
- COM: 20
- ATC: 15
newScore:
- name: CVI
  value: 18
- name: INC
  value: 32
- name: COM
  value: 20
- name: ATC
  value: 15
compoundScore:
  CVI: 18
  INC: 32
  COM: 20
  ATC: 15
---
questionUrl:: http://forum.obsidian.md/t//74265


## Using `finalScore`

Faulty retrieveal: `= this.finalScore.CVI + this.finalScore.INC `

finalScore: `= this.finalScore[0].CVI + this.finalScore[1].INC `

## Using `newScore`

Names: `= this.newScore.name `

Sum: `= sum(this.newScore.value) `

## Using `compoundScore`

Full object: `= this.compoundScore`

Sum: `= this.compoundScore.CVI + this.compoundScore.COM + this.compoundScore.INC + this.compoundScore.ATC `

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