Power BI / DAX:通过添加的列值过滤SUMMARIZE或GROUPBY

时间:2019-10-04 12:10:43

标签: filter powerbi dax summarize

由于数据的机密性质,我将尝试使用一些随机示例来描述我正在努力解决的问题。 假设我在Power BI中有一个包含发票数据的事实表。我需要计算出在过去12个月内销售额超过50000欧元(或更确切地说,在所选日期之前的12个月内)的销售额超过不同产品ID的数量。同时,我需要能够将搜索结果缩小到所选的国家/地区,产品组和产品类别。

我首先像这样设置DATESBETWEEN的日期范围:

productsCount = 
VAR lastDay = IF(MAX('Calendar table'[Date]) > NOW(); NOW(); MAX('Calendar table'[Date]))
VAR firstDay = EDATE(lastDay; -12)
RETURN

但是我迷路了:

CALCULATE(
    COUNTROWS('Sales');
    SUMMARIZE(
        'Sales';
        'Sales'[ProductID];
        "prodSales"; SUM('Sales'[EUR])
    );
    DATESBETWEEN('Sales'[Date]; firstDay; lastDay);
    ALLEXCEPT(
        'Sales';
        'Sales'[Product group];
        'Sales'[Product category];
        'Sales'[Country]
    );
    [prodSales] > 50000
)

问题是,我需要能够在统计行数之前按销售总额过滤汇总数据。

3 个答案:

答案 0 :(得分:0)

您可以在power查询编辑器中创建一个汇总表,然后在dax中创建一个度量以过滤超过50k的结果。

答案 1 :(得分:0)

我还没有测试过,但是我认为在总结后进行过滤的地方,这样的事情可能会起作用:

productsCount =
VAR lastDay =
    IF (
        MAX ( 'Calendar table'[Date] ) > NOW ();
        NOW ();
        MAX ( 'Calendar table'[Date] )
    )
VAR firstDay = EDATE ( lastDay; -12 )
RETURN
    COUNTROWS (
        FILTER (
            CALCULATETABLE (
                SUMMARIZE ( 'Sales';
                   'Sales'[ProductID];
                   "prodSales"; SUM ( 'Sales'[EUR] )
                );
                DATESBETWEEN ( 'Sales'[Date]; firstDay; lastDay );
                ALLEXCEPT (
                    'Sales';
                    'Sales'[Product group];
                    'Sales'[Product category];
                    'Sales'[Country]
                )
            );
            [prodSales] > 50000
        )
    )

答案 2 :(得分:0)

总而言之,我们可以在汇总表之后进行过滤

我的输入表是

enter image description here

我正在写查询

App Downlaod Count = 

FILTER(
    SUMMARIZE(events_intraday,
    events_intraday[event_name],
    events_intraday[event_date],
    events_intraday[platform],
    events_intraday[stream_id],
    "Count",CALCULATE(
        COUNT(events_intraday[event_name]),
            FILTER(events_intraday,
                    (events_intraday[platform] = "ANDROID" || 
                    events_intraday[platform] = "IOS")
                )
            )
        ),
        events_intraday[event_name] = "first_open" && 
        (events_intraday[stream_id] = "1415470954" || 
        events_intraday[stream_id] = "1420775080")
    )

输出为

enter image description here