# Aggregating by Week interval

#1

c3ShowType(Interval) doesn’t appear to have an interval between DAY and MONTH, and I’m looking to aggregate by week (specifically, always M-Sun). I saw a previous post that suggested:

c3Viz(Facility.evalMetrics({start:‘2015-11-16T00:00:00.000Z’,end:‘2016-11-13T21:59:59.999Z’,ids:[‘15’], expressions:[“DayOfWeek==1 ? window(‘SUM’,energySpend,1,7): (DayOfWeek==2 ? window(‘SUM’,energySpend,0,1) +window(‘SUM’,energySpend,1,6) : (DayOfWeek==3 ? window(‘SUM’,energySpend,-1,2)+window(‘SUM’,energySpend,1,5):(DayOfWeek==4 ? window(‘SUM’,energySpend,-2,3)+window(‘SUM’,energySpend,1,4) :(DayOfWeek==5 ? window(‘SUM’,energySpend,-3,4) +window(‘SUM’,energySpend,1,3):(DayOfWeek==6 ? window(‘SUM’,energySpend,-4,5) +window(‘SUM’,energySpend,1,2):(DayOfWeek==7 ? window(‘SUM’,energySpend,-5,6) +window(‘SUM’,energySpend,1,1) :0.0))))))”], interval:‘DAY’}))*

Is this the recommended route, or are there other suggested options?

0 Likes

#2

there is no `WEEK` interval so you have to evaluate per day than aggregate. `DayOfWeek` help you check what day of week it is just like in your example. You may better refactor your metric into a combination of Simple and Compound metrics so that you don’t endup with a so long expression.

0 Likes