PowerPivot formula for row wise weighted average

徘徊边缘 提交于 2019-12-25 02:57:52

问题


I have a table in PowerPivot which contains the logged data of a traffic control camera mounted on a road. This table is filled the velocity and the number of vehicles that pass this camera during a specific time(e.g. 14:10 - 15:25). Now I want to know that how can I get the average velocity of cars for an specific hour and list them in a separate table with 24 rows(hour 0 - 23) where the second column of each row is the weighted average velocity of that hour? A sample of my stat_table data is given below:

count   vel         hour  
-----   ---         ----  
133     96.00237    15  
117     91.45705    21  
81      81.90521    6  
2       84.29946    21  
4       77.7841     18  
1       140.8766    17  
2       56.14951    14  
6       71.72839    13  
4       64.14309    9  
1       60.949      17  
1       77.00728    21  
133     100.3956    6  
109     100.8567    15  
54      86.6369     9  
1       83.96901    17  
10      114.6556    21  
6       85.39127    18  
1       76.77993    15  
3       113.3561    2  
3       94.48055    2

In a separate PowerPivot table I have 24 rows and 2 columns but when I enter my formula, the whole rows get updated with the same number. My formula is:
=sumX(FILTER(stat_table, stat_table[hour]=[hour]), stat_table[count] * stat_table[vel])/sumX(FILTER(stat_table, stat_table[hour]=[hour]), stat_table[count])


回答1:


  1. Create a new calculated column named "WeightedVelocity" as follows

    WeightedVelocity = [count]*[vel]
    
  2. Create a measure "WeightedAverage" as follows

    WeightedAverage = sum(stat_table[WeightedVelocity]) / sum(stat_table[count])
    
  3. Use measure "WeightedAverage" in VALUES area of pivot Table and use "hour" column in ROWS to get desired result.



来源:https://stackoverflow.com/questions/29746810/powerpivot-formula-for-row-wise-weighted-average

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!