Power BI-统计

时间:2019-01-30 14:29:15

标签: powerbi dax

我有下表,并尝试从excel转到Power Bi。在excel中,我使用=COUNTIFS($A$2:$A$16,"<="&E2,$B$2:$B$16,">="&E2)来获取Count值,但我想知道如何在Power BI中计算它

open_date   close_date          Date        Count
16-Sep-18   14-Jan-19           16-Sep-18   1
21-Sep-18   19-Jan-19           17-Sep-18   1
23-Sep-18   21-Jan-19           18-Sep-18   1
17-Jan-19   27-Jan-19           19-Sep-18   1
26-Jan-19   28-Jan-19           20-Sep-18   1
27-Jan-19   28-Jan-19           21-Sep-18   2
19-Jan-19   19-Jan-19           22-Sep-18   2
19-Jan-19   29-Jan-19           23-Sep-18   3
27-Jan-19   29-Jan-19           24-Sep-18   3
20-Jan-19   30-Jan-19           25-Sep-18   3
23-Jan-19   30-Jan-19           26-Sep-18   3
26-Jan-19   30-Jan-19           27-Sep-18   3
28-Jan-19   30-Jan-19           28-Sep-18   3
21-Jan-19   31-Jan-19           29-Sep-18   3
25-Jan-19   31-Jan-19           30-Sep-18   3

1 个答案:

答案 0 :(得分:3)

有多种方法可以执行此操作,但是它们都将使用某种过滤方式。

以下是几个示例:

CountIf =
COUNTROWS (
    FILTER (
        ALL ( Table1 ),
        Table1[open_date] <= MAX ( Table1[Date] ) &&
        Table1[close_date] >= MAX ( Table1[Date] )
    )
)

CountIf =
VAR CurrentDate =
    MAX ( Table1[Date] )
RETURN
    CALCULATE (
        COUNT ( Table1[Date] ),
        ALL ( Table1 ),
        Table1[open_date] <= CurrentDate,
        Table1[close_date] >= CurrentDate
    )