1

Previously, I asked about how we can fetch a simple previous row through an incremented ID field (Thank you Petr Havlík). In this case I have ID and ACTIVITY, where (ACTIVITY&ID) is the unique value per row.

From an SQL perspective I just do an inner join where ACTIVITY = Joined ACTIVITY and ID = ID - 1 in the joined table and get the row I need.

In other words, I want the previous percentage belonging to the same activity.

So using the answer in the previous post I was able to get the result I want on 1000 rows. However if I were to increase this number of rows to 85000+ this function is dauntingly slow.

=SUMX(FILTER ( Query, (EARLIER ( [ID] ) = [ID] + 1)&&(EARLIER([ACTIVITY])=[ACTIVITY])),[PERCENTAGE])

My end result is to make this function on up to 7 million rows, if this is possible, how I can optimize it ? And if it isn't, could you explain to me why I can't do it ?

Fetching previous rows with the same ID and Activity

4

3 回答 3

3

一种选择可能是尝试该方法的变体-没有您的数据集,我无法测试它是否更有效,但我已经在 1m+ 行数据集上运行了类似的东西而没有问题:

=
CALCULATE (
    SUM ( [PERCENTAGE] ),
    FILTER (
        Query,
        [ID] = EARLIER ( [ID] ) - 1
        && [ACTIVITY] = EARLIER ( [ACTIVITY] )
    )
)

可能不是您想听到的,但在导入时使用 SQL 执行此操作可能是您最好的选择。

于 2014-11-18T16:56:53.423 回答
2

这里最好的答案是使用 Lookupvalue,它会绕过您需要做的任何过滤器,并允许您直接查找表中的值。这会快得多。

它看起来像:

=LOOKUPVALUE(table[PERCENTAGE], [ID] = EARLIER ( [ID] ) - 1)

请确保 ID 值是唯一的,因为 lookupvalue 只能返回一个结果,当返回多行时会出错。你可以用 iserror 包裹它

= IF(ISERROR(LOOKUPVALUE(table[PERCENTAGE], [ID] = EARLIER ( [ID] ) - 1)), BLANK()
           , LOOKUPVALUE(table[PERCENTAGE], [ID] = EARLIER ( [ID] ) - 1)
            )
     )
于 2014-11-18T22:00:43.880 回答
2

杰什梅

这几乎是同一个问题 - 正如 Jacob 所建议的,您可以使用Excel/PowerPivot 中通常可用的逻辑运算符。

你真的可以为此发疯,如果你需要更复杂的东西 - 例如在其他条件下获得两点之间的差异,我会向你指出非常相似的问题和我对它们的回答:

希望这可以帮助 :)

于 2014-11-18T22:03:55.093 回答