Power Pivot 先前值
Power Pivot previous value
我有以下 table & 可以在 Excel PowerPivot
中看到的数据
项目、时间范围、总计
1, 1, 15
1, 2, 20
1, 3, 15
2, 1, 10
2, 2, 11
2, 3, 10
虽然我可以轻松获得最后一个时间范围,但我需要获得前一个时间范围的总数,例如:
项目,时间范围,总计,last_timeframe,last_timeframe_总计
1, 1, 15, 0, 0
1, 2, 20, 1, 15
1、3、15、2、20
2、1、10、0、0
2, 2, 11, 1, 10
2, 3, 10, 2, 11
我试过一个计算公式,但它似乎不起作用,只有 returns 个空白。 =CALCULATE(SUM(MyTable[total]), MyTable[timeframe] = EARLIER(MyTable[timeframe]) - 1)
EARLIER() 不理解任何类型的行排序。
EARLIER() 引用嵌套行上下文。
您真正需要的是此处的 LOOKUPVALUE(),它将指定字段中的值与您提供的搜索条件相匹配,returns匹配这些条件的行的存在值。
根据您的示例,[Timeframe] 似乎是每个项目的单递增索引。如果这个假设不成立,LOOKUPVALUE() 可能不是您想要的函数。
last_timeframe_total =
LOOKUPVALUE(
MyTable[total]
,MyTable[item] // This is the field we're searching
,MyTable[item] // This is the value to search for in the field
// identified in argument 2 - this evaluates
// in the current row context of the table
// where we are defining last_timeframe_total
// as a calculated column.
,MyTable[timeframe] // The second field we are searching.
,MyTable[timeframe] - 1 // Similar to argument 3.
)
这将为您提供当前项目的先前时间范围内的值。
Ninja 编辑:忘记提及 Power Pivot 并不是真正用于执行此类工作的层。查找和此类数据整形最好在您的 ETL 中从事务源中完成。如果这不可能,那么最好在查询中完成以填充 Power Pivot,而不是在 Power Pivot 中。 Power Query 是用于此类转换的好工具,它很容易融入 Microsoft 生态系统,是 Excel.
的另一个 Microsoft 插件
Power Pivot 是一个针对聚合优化的分析数据库。一般而言,如果您发现自己在思考 "for every row,",则表明您尝试完成的工作可能更适合 BI 解决方案的不同层。
我有以下 table & 可以在 Excel PowerPivot
中看到的数据项目、时间范围、总计
1, 1, 15
1, 2, 20
1, 3, 15
2, 1, 10
2, 2, 11
2, 3, 10
虽然我可以轻松获得最后一个时间范围,但我需要获得前一个时间范围的总数,例如:
项目,时间范围,总计,last_timeframe,last_timeframe_总计
1, 1, 15, 0, 0
1, 2, 20, 1, 15
1、3、15、2、20
2、1、10、0、0
2, 2, 11, 1, 10
2, 3, 10, 2, 11
我试过一个计算公式,但它似乎不起作用,只有 returns 个空白。 =CALCULATE(SUM(MyTable[total]), MyTable[timeframe] = EARLIER(MyTable[timeframe]) - 1)
EARLIER() 不理解任何类型的行排序。
EARLIER() 引用嵌套行上下文。
您真正需要的是此处的 LOOKUPVALUE(),它将指定字段中的值与您提供的搜索条件相匹配,returns匹配这些条件的行的存在值。
根据您的示例,[Timeframe] 似乎是每个项目的单递增索引。如果这个假设不成立,LOOKUPVALUE() 可能不是您想要的函数。
last_timeframe_total =
LOOKUPVALUE(
MyTable[total]
,MyTable[item] // This is the field we're searching
,MyTable[item] // This is the value to search for in the field
// identified in argument 2 - this evaluates
// in the current row context of the table
// where we are defining last_timeframe_total
// as a calculated column.
,MyTable[timeframe] // The second field we are searching.
,MyTable[timeframe] - 1 // Similar to argument 3.
)
这将为您提供当前项目的先前时间范围内的值。
Ninja 编辑:忘记提及 Power Pivot 并不是真正用于执行此类工作的层。查找和此类数据整形最好在您的 ETL 中从事务源中完成。如果这不可能,那么最好在查询中完成以填充 Power Pivot,而不是在 Power Pivot 中。 Power Query 是用于此类转换的好工具,它很容易融入 Microsoft 生态系统,是 Excel.
的另一个 Microsoft 插件Power Pivot 是一个针对聚合优化的分析数据库。一般而言,如果您发现自己在思考 "for every row,",则表明您尝试完成的工作可能更适合 BI 解决方案的不同层。