Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
suppose I have a table with a Start and End date.
I have a calendar table interval-matched to these two dates.
The user chooses a month -> all intervals which intersect with this month are filtered in.
I need to calculate the average interval length on these simple rules:
I can't seem to figure it out how to compare the End of each row with the Maximum selected day.
For example this:
=avg(if(max(Date) >= End, End - Start, max(Date) - Start))
does not work.
Bellow is an example for how it should work. The same example is in the attached files.
Thank is advance for any helpful comments.
Start | End | User Selects January 2013 | |
1.1.2013 | 15.2.2013 | 30 | |
10.1.2013 | 15.2.2013 | 21 | |
1.1.2013 | 15.1.2013 | 14 | |
1.1.2013 | 28.2.2013 | 30 | |
1.2.2013 | 15.2.2013 | ||
1.1.2013 | 15.1.2013 | 14 | |
15.1.2013 | 31.1.2013 | 16 | |
15.2.2013 | 28.2.2013 | ||
15.1.2013 | 15.2.2013 | 16 | |
25.1.2013 | 15.2.2013 | 6 | |
Avg = | 18,375 |
Try this
avg(if(max(TOTAL Date)>=End,(End-Start),max(TOTAL Date) - Start))
May be like attached sample?
Update:
For total average work properly, tweak the expression a bit, put avg() around the existing expression like:
=Avg(Aggr(avg(if(max(total Date) >= End, End - Start, max(total Date) - Start)),Dimension) )
Try this
avg(if(max(TOTAL Date)>=End,(End-Start),max(TOTAL Date) - Start))
Thank you both for helpful answers!
I have based my solution on Mohit's solution. The TOTAL keyword was the key missing in my previous attempts.
I had to solve one more problem: because I did the average difference on two date fields which I also used in an intervalmatch without generating a synthetic key, my expression was calculated only on these distinct combination of dates from the interval table.
I have solved it by generating copies of the two date fields in the main table, which I used for the calculations.