Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
tiklabaq
Creator
Creator

Aggr value between begin and end date

Hi Guys,

following issue.

I want to show in a chart the value of contracts. These data are given:

contractbeginendtotal value
12301.01.201431.12.2018100 000
12401.01.201531.05.2016500 000
23410.03.201630.11.20196 000 000

It's a bar chart with yearmonth as dimension. In this chart I want to see the total value of contracts per month based on begin and end date.

for example:

yearmonthtotal value
2015-05600 000
2016-066 100 000
2019-016 000 000

So the value should not be cumulated per day or month, rather show only the total value for all contracts which are valid in this period.

Do you have an idea

1 Solution

Accepted Solutions
tiklabaq
Creator
Creator
Author

Hi Sunny,

I've solved it. Really simple

  1. intervalmatch with date
  2. expression: sum(value) / count(distinct date) --> result is the avg per dimension
  3. now the chart shows the right values for month, year and so on

I think this is the best way.

Thank you

View solution in original post

17 Replies
sunny_talwar

Are you using IntervalMatch in your script to link month-year to begin and end?

tiklabaq
Creator
Creator
Author

Hi Sunny,

No, I do not do that because I do not want to generate unnecessary data

sunny_talwar

Oh, so the two tables are not linked to each other on anything?

tiklabaq
Creator
Creator
Author

Yes, exactly, I thought we could solve this without intervalmatch?

And suppose I did it with intervalmatch, how do I display each value only once a month or a year?

sunny_talwar

1st you don't have to use interval match, but a Cartesian Product on the front end which will use an if statement is not going to give you a good performance if you have a lot of data to work with

2nd you can intervalmatch with the monthstart rather than all dates and this should keep a single value for each month (I believe)

tiklabaq
Creator
Creator
Author

no, there are not so many data, with IF I have also got good results, but if I use as dimension date and not month. Because at months it accumulates the value in the chart for each day and displays the sum of every single day.

sunny_talwar

What expression are you using?

tiklabaq
Creator
Creator
Author

sum(if(Date >= begin and Date <= end, total value))

sunny_talwar

How about if you do this

Sum(If(Date >= begin and Date <= end and Date = MonthStart(Date), total value))