Power BI - 使用 Dax 基于 Group By 进行过滤
Power BI - Using Dax to Filter Based on a Group By
我是 DAX 新手。
假设我有一个 table 看起来像这样:
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查询returnTableA行状态在table中至少出现两次,加上行数的计数一样的状态。在 Power BI 中,我们可以编写一个计算 table,将相同状态的行数相加,然后过滤掉那些小于 2
的行数
Result =
FILTER(
ADDCOLUMNS(
'Table A',
"row_count",
CALCULATE(
COUNTROWS( 'Table A' ),
ALLEXCEPT( 'Table A', 'Table A'[Status] )
)
),
[row_count] > 1
)
我是 DAX 新手。
假设我有一个 table 看起来像这样:
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查询returnTableA行状态在table中至少出现两次,加上行数的计数一样的状态。在 Power BI 中,我们可以编写一个计算 table,将相同状态的行数相加,然后过滤掉那些小于 2
的行数Result =
FILTER(
ADDCOLUMNS(
'Table A',
"row_count",
CALCULATE(
COUNTROWS( 'Table A' ),
ALLEXCEPT( 'Table A', 'Table A'[Status] )
)
),
[row_count] > 1
)