I have daily notes (with a name format of “yyyyMMdd ccc” like “20240206 Tue”) within which some have a “Run Distance” field for the distance I ran that day. I would like to get a sum of the distance I ran each week for the last four weeks.

### Things I have tried

I started with this query:

```
Table without ID durationformat(date(today) - date(file.name, "yyyyMMdd ccc"), "w") as "Week", sum(run-distance) as "Distance"
from "@Journal/Daily/2024"
where date(today) - date(file.name, "yyyyMMdd ccc") < dur(4 weeks)
where run-distance > 0
```

this gives the following results:

Week | Distance |
---|---|

3 | 7.32 |

3 | 6.29 |

2 | 6.32 |

2 | 1 |

2 | 6.31 |

1 | 1.25 |

1 | 6.31 |

1 | 7.3 |

0 | 1.05 |

0 | 6.31 |

0 | 1.25 |

0 | 6.29 |

So far, so good! I then added a group by (group by Week) which gave me an error:

```
Dataview: Every row during final data extraction failed with an error; first 3:
- No implementation of 'date' found for arguments: null, string
```

So then I changed the query to move the calculation of week to the Group By line as I’ve seen in some examples on this forum:

```
Table without ID Week, sum(run-distance) as "Distance"
from "@Journal/Daily/2024"
where date(today) - date(file.name, "yyyyMMdd ccc") < dur(4 weeks)
where run-distance > 0
group by durationformat(date(today) - date(file.name, "yyyyMMdd ccc"), "w") as "Week"
```

This now gives this result:

Week | Distance |
---|---|

0 | - |

1 | - |

2 | - |

3 | - |

Which seems pretty close. But how do I get the Distance to be the actual sum versus the dash?

I’ve tried various combinations of Group By and Flatten for both Week and Distance as I’ve seen other examples on this forum, but honestly, most of those are much more complicated than mine (multiple group by, multiple flatten), so they haven’t helped me get closer to a solution.

Thanks for any feedback!