![](/img/trans.png)
[英]How to sum only common rows based on the filter dynamically using DAX in Power Bi?
[英]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.