[英]Power BI - Using Dax to Filter Based on a Group By
I am new to DAX.我是 DAX 的新手。
Let's pretend I have a table that looks like this:假设我有一张如下所示的表格:
Table A:
status delivered sold
late 10 50
late 20 300
early 5 500
Let's pretend I am using this SQL query:假设我正在使用这个 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]
What would be the dax equivalent of this? dax 相当于什么?
The SQL query return the Table A rows with the status that occurrs at least twice in the table, adding the count of the number of rows with the same status. SQL 查询返回表 A 中状态至少出现两次的行,加上相同状态的行数。 In Power BI we can write a calculated table that adds the count of the rows of the same status and then filter out those with a count less than 2
在 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.