# Calculating averages in dataview

**URL:** <https://forum.obsidian.md/t/calculating-averages-in-dataview/59929>\
**Category:** Help\
**Tags:** dataview\
**Created:** [May 17, 2023, 5:55pm UTC](https://forum.obsidian.md/t/calculating-averages-in-dataview/59929 "2023-05-17T17:55:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inamati](https://forum.obsidian.md/user_avatar/forum.obsidian.md/inamati/32/43789_2.png) [@Inamati](https://forum.obsidian.md/u/Inamati)\
**Post date:** [May 17, 2023, 5:55pm UTC](https://forum.obsidian.md/t/calculating-averages-in-dataview/59929/1 "2023-05-17T17:55:21Z")

</div>

Hello everyone,  
I am having a hard time understanding how averages are done in dataview. I have looked at some posts in the forum but I can’t understand how they work.

I have an existing and working query that gets me the total MTTC of my tickets.

```auto
TABLE WITHOUT ID row.key AS Days, MTTC
WHERE contains(file.name,"INC") OR contains(file.name,"SCTASK") AND !contains(Closed, null) AND !contains(Created, null)
FLATTEN (Closed - Created).days AS MTTC
GROUP BY MTTC
FLATTEN length(rows.MTTC) as MTTC

```

What I need is to get the weekly average MTTC. Can someone help?

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [May 17, 2023, 11:08pm UTC](https://forum.obsidian.md/t/calculating-averages-in-dataview/59929/2 "2023-05-17T23:08:03Z")

</div>

What is the `MTTC` ? You’re defining it twice with two different values:

- Once as kind of a duration doing the `(Closed - Created).days as MTTC
- Once as `length(rows.MTTC) as MTTC`

Which would you like the average of?

---

<div class="post-metadata">

**Author:** ![Inamati](https://forum.obsidian.md/user_avatar/forum.obsidian.md/inamati/32/43789_2.png) [@Inamati](https://forum.obsidian.md/u/Inamati)\
**Post date:** [May 18, 2023, 8:20am UTC](https://forum.obsidian.md/t/calculating-averages-in-dataview/59929/3 "2023-05-18T08:20:12Z")

</div>

MTTC is the difference between the closed and the created date. What I want is the average MTTC for each week.

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [May 18, 2023, 9:36am UTC](https://forum.obsidian.md/t/calculating-averages-in-dataview/59929/4 "2023-05-18T09:36:45Z")

</div>

To get a weekly average you need to connect your MTTC to a week number, and then group in that week number. Then you can do an `average(rows.MTTC)`.

So get your query to report back the week number and the MTTC column for starters. Then you add the group by statement and replace the columns with the average statement.

---

<div class="post-metadata">

**Author:** ![Inamati](https://forum.obsidian.md/user_avatar/forum.obsidian.md/inamati/32/43789_2.png) [@Inamati](https://forum.obsidian.md/u/Inamati)\
**Post date:** [May 18, 2023, 2:13pm UTC](https://forum.obsidian.md/t/calculating-averages-in-dataview/59929/5 "2023-05-18T14:13:13Z")

</div>

Can you help me with the code itself?

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [May 18, 2023, 5:12pm UTC](https://forum.obsidian.md/t/calculating-averages-in-dataview/59929/6 "2023-05-18T17:12:17Z")

</div>

I’ve given you the tools you need, and I don’t have the details of your setup (or intentions), so “No, I can’t write the code for you.”

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [August 16, 2023, 5:13pm UTC](https://forum.obsidian.md/t/calculating-averages-in-dataview/59929/7 "2023-08-16T17:13:16Z")

</div>

Closed on August 16, 2023, 5:13pm UTC

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