2

I have a PowerPivot table for which I need to be able to determine how long an item was in an Error state. My data set looks something like this:

enter image description here

What I need to be able to do is to look at the values in the ID and State columns, and see if the value in the previous row is ERROR in the State column, and the same in the ID column. If it is, I then need to calculate the difference between the Changed Date values in those two rows.

So, for example, when I got to row 4, I would see that the value in the State column for Row 3, the previous row, is ERROR, and that the value in the ID column in the previous row is the same as the current row, so I would then calculate the difference between the Changed Date values in Row 3 and Row 4 (I don't care about the values in any of the other columns for this particular requirement).

Is there a way to do this in PowerPivot? I've done a fair amount of Internet searching, and it looks like if it can be done, it would use the EARLIER or EARLIEST DAX functions, but I can't find anything that tells me how, or even if, this can be done.

Thanks.

4

1 回答 1

3

克里斯_

我有很多次类似的要求,经过很长时间的反复试验,我终于明白了EARLIER是如何工作的。它可能非常强大,但也非常缓慢,因此请始终检查您的计算性能。

要回答您的问题,您需要创建 4 个计算列:

1) Item Rank - 用于对具有相同Item ID的问题进行排名

=COUNTROWS(FILTER('ID', EARLIER([Item ID]) = [Item ID] && EARLIER([Date]) >= [Date]))

2)跟随错误- 轻松找到跟随错误问题问题

=IF([State] = "EROR",[Item Rank]+1)

3)跟踪问题的时间- 简单的查找,以便您可以计算不同的

=IF([Follows Error]>0, 
  LOOKUPVALUE([Date], [User], [User], [Item Rank], [Follows Error]), 
  BLANK()
)

4) Time Diff - 针对特定问题计算不同的时间

=IF([State]="EROR",
  DAY([Time of Following Issue])-DAY([Date]),
  BLANK()
)

使用这些计算列,您可以轻松地创建一个 powerpivot 表,将StateItem Id拖到ROWS窗格中,然后简单地将Time Diff添加到Values。您将大致了解包含字符串“EROR”问题的问题以及解决这些问题所花费的时间。

这是它在 PowerPivot 窗口中的样子:

在此处输入图像描述

以及由此产生的数据透视表:

在此处输入图像描述

您可以在此处下载我的Excel 文件(2013 年)。

正如我所提到的,请注意性能,因为具有嵌套 EARLIER 和 IF 条件的计算列可能对性能要求过高。如果有更聪明的方法,我会很高兴看到它,但现在这对我来说很好。

另外,请记住,所有计算的列都可以嵌套到 1 中,但我将它们分开以便更容易理解公式。

希望这可以帮助 :-)

于 2014-10-08T23:10:27.607 回答