averagex
I am trying to calcualte the daily average of flight hours for an aircraft that has multiple flights per day for a number of days (the aircraft doesn't fly every day). I am first summing the hours flown per day, and then averaging the sum of the daily hours flown over a period of time (there's a Min and Max Date that the user selects to perform the evaluation). Here's some sample data:
| Aircraft | Date | Hours |
| N111PD | 1/1/2016 | 2 |
| N111PD | 1/1/2016 | 3 |
| N111PD | 1/1/2016 | 1 |
| N111PD | 1/2/2016 | 4 |
| N111PD | 1/2/2016 | 3 |
| N111PD | 1/2/2016 | 1 |
| N111PD | 1/4/2016 | 5 |
| N111PD | 1/4/2016 | 1 |
| N111PD | 1/4/2016 | 4 |
| N111PD | 1/4/2016 | 2 |
| N111PD | 1/7/2016 | 5 |
| N111PD | 1/7/2016 | 6 |
To sum the hours per day I am using the following formula (agian, the user selects the MIN and MAX Dates):
CumulativeDailyHours =
CALCULATE(
sum(Table[Date]),
FILTER(
ALL (Table[Date],
Table[Date] <= MAX(Table[Date] &&
Table[Date] > MIN(Table[Date])
)
)
That seems to be working (please let me know if you think I'm missing something), but when I try to come up with a daily average I get a "(Blank)" in the card that I am using to show the Average Daily Hours Flown. Here's the calcualtion for the average hours that I am using:
AvgDailyHours =
AVERAGEX (Table, [CumulativeDailyHours])
I'm thinking that AVERAGEX is having a problem with the fact that there aren't flights every day and so it doesn't know what to do with the non-flying days, but I have tried to do various ways to fill in the non-flying days with a "0" (IF(ISBLANK(.....), but even that doesn't seem to work.
This should be realtively easy calculation but for some reason I can't seem to get it to work.
Thanks
Hi, Try this please:
1. Create a measure to count the days between the range selected in Date Slicer (Plus 1)
DayBetweenFirst&LastDaySelected+1 = DATEDIFF ( MIN ( AirCraft[Date] ), MAX ( AirCraft[Date] ), DAY ) + 1
2. Create a measure to calculate the Average Daily Hour
AverageDailyHour = DIVIDE ( SUM ( AirCraft[Hours] ), [DayBetweenFirst&LastDaySelected+1] )