我有一个问题,我希望一些更有经验的DAX程序员可以帮助我 . 我一直在尝试在Excel 2013 / PowerPivot / PowerView中开发仪表板,我想要显示的图形之一是按小时计算的中位数性能线图 . 然后,我想基于单独的列使用我的性能指标过滤数据集,并将其链接到切片器 . 应该相对于过滤的数据集计算中位数 . 对于中位数计算,我试图调整Marco Russo提出的公式(http://sqlblog.com/blogs/marco_russo/archive/2010/07/20/median-calculation-in-dax.aspx) .
为了说明这个问题,假设我有两个表 - main_table 和 other_table . Main_table 有4列 - RowID , hour_of_day , performance_metric 和 category . Other_table 有两列 hour_of_day 和 median_column . 我的目标是为 median_column 找到一个公式,使其按小时显示中位数绩效指标,但仍可按 category 进行切分 . 我试图用于中位数的公式是
=CALCULATE(
MINX(
FILTER(
VALUES(main_table[performance_metric]),
CALCULATE(
COUNTA(main_table[performance_metric]),
main_table[performance_metric] <= EARLIER(main_table[performance_metric]))
> COUNTA(main_table[performance_metric]/2),
main_table[performance_metric]),
FILTER(
main_table,
main_table[hour_of_day] = EARLIER(other_table[hour_of_day])))
或者没有格式化:
=CALCULATE(MINX(FILTER(VALUES(main_table[performance_metric]), CALCULATE(COUNTA(main_table[performance_metric]), main_table[performance_metric] <= EARLIER(main_table[performance_metric])) > COUNTA(main_table[performance_metric]/2), main_table[performance_metric]), FILTER(main_table, main_table[hour_of_day] = EARLIER(other_table[hour_of_day])))
但是,当我在 main_table 中创建基于 category 的切片器时,我的图表似乎不受切片器的影响 . 我的理解是,通过将 main_table 而不是 ALL(main_table) 作为最后一次FILTER调用中的第一个参数,我的中位数计算将受到应用于 main_table 的切片和过滤器的影响 . 我错过了一些明显的东西吗?
1 回答
计算列显然是在执行查询之前计算的,因此必须将需要受切片器影响的任何内容作为度量输入,而不是计算列 .
这里更详细地回答(http://www.mrexcel.com/forum/powerpivot-questions/741071-medians-context-issues-dax.html#post3641780)