簡體   English   中英

Power BI - 使用 Dax 根據 Group By 進行篩選

[英]Power BI - Using Dax to Filter Based on a Group By

我是 DAX 的新手。

假設我有一張如下所示的表格:

Table A:

status     delivered    sold
late       10           50
late       20           300
early      5            500

假設我正在使用這個 SQL 查詢:

with cte_1 as (

select 
status, count(*) as [row_count]
from [table a]
group by [status]
having count(*) > 1

)

select *
from [table a] as p1
inner join [cte_1] as p2
on p1.[status] = p2.[status]

dax 相當於什么?

SQL 查詢返回表 A 中狀態至少出現兩次的行,加上相同狀態的行數。 在 Power BI 中,我們可以編寫一個計算表,將相同狀態的行的計數相加,然后過濾掉計數小於 2 的行

Result =
FILTER(
    ADDCOLUMNS(
        'Table A',
        "row_count",
            CALCULATE(
                COUNTROWS( 'Table A' ),
                ALLEXCEPT( 'Table A', 'Table A'[Status] )
            )
    ),
    [row_count] > 1
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM