基于Power Bi中同一列中的上一行和另一列中的上一行进行计算

时间:2018-12-19 08:05:34

标签: powerbi dax powerbi-desktop

我试图按以下方法在功率Bi中计算NoofEventsInQueue列。 157是事件的总数

enter image description here

1 个答案:

答案 0 :(得分:1)

在计算列中:

NumberOfEventsInQueue = 
IF ( 
    ISBLANK ( Table1[NoOfEventsAtATime] ),
    BLANK(),
    CALCULATE ( 
        SUM ( Table1[NoOfEventsAtATime] ),
        FILTER ( 
            ALL ( Table1 ),
            Table1[Ref_Time] >= EARLIER ( Table1[Ref_Time] )
        )
    )
)

如果您的NoOfEventsAtATime列中间有空白行,并且仍然希望在计算所得的列中返回一个值,则可以使用以下方式:

NumberOfEventsInQueue = 
VAR TimeMin = 
    CALCULATE ( 
        MIN ( Table1[Ref_Time] ),
        FILTER ( 
            ALL ( Table1 ),
            NOT ISBLANK ( Table1[NoOfEventsAtATime] )
        )
    )
VAR TimeMax = 
    CALCULATE ( 
        MAX ( Table1[Ref_Time] ),
        FILTER ( 
            ALL ( Table1 ),
            NOT ISBLANK ( Table1[NoOfEventsAtATime] )
        )
    )
VAR Output = 
    IF ( 
        Table1[Ref_Time] >= TimeMin && Table1[Ref_Time] <= TimeMax,
        CALCULATE ( 
            SUM ( Table1[NoOfEventsAtATime] ),
            FILTER ( 
                ALL ( Table1 ),
                Table1[Ref_Time] >= EARLIER ( Table1[Ref_Time] )
            )
        ),
        BLANK()
    )
RETURN Output