将 SQL 子查询转换为 Power BI DAX
Convert SQL subquery to Power BI DAX
作为PowerBI的新手,我曾被这个问题困扰过。我想创建一个自定义度量,可以使用 SQL 语句轻松解决,如下所示:
select count(*) from Task
where case_num in(
select case_num from Task
where task_type="DDD") sub
有人可以帮我解决这个问题吗?谢谢!!!!!
The table is roughly like this
试试这个措施
_count =
CALCULATE ( COUNT ( Task[CaseNum] ), FILTER ( Task, Task[task_type] = "DDD" ) )
Edit
如果您想在过滤器中使用少量任务,可以使用此
Measure =
CALCULATE ( COUNT ( Task[Case] ), FILTER ( Task, Task[task_type] IN {"BB","AA","DDD","CC"}))
如果您不想在过滤器中手动输入大量任务,请先创建一个查找 table 并在度量中使用它
TaskLookUpTable = DATATABLE ( --a long list of task; hence taskTbl
"task_type", STRING,
{
{ "BB"},
{ "AA"},
{ "DDD"},
{ "CC"}
}
)
Measure2 = --create the above table first before writing this measure
CALCULATE (
COUNT ( Task[Case] ),
TREATAS ( VALUES ( 'TaskLookUp'[task_type] ), Task[task_type] )
)
您可以隔离具有特定任务类型的 case_nums
VAR tbl = CALCULATETABLE(VALUES('Table'[case_num]),'Table'[task_type] = "DDD")
然后应用 table 作为过滤器:
Measure =
VAR tbl = CALCULATETABLE(VALUES('Table'[case_num]),'Table'[task_type] = "DDD")
RETURN CALCULATE(COUNT('Table'[case_num]), TREATAS(tbl,'Table'[case_num]))
或
Measure =
VAR tbl = CALCULATETABLE(VALUES('Table'[case_num]),'Table'[task_type] = "DDD")
RETURN CALCULATE(COUNT('Table'[case_num]), 'Table'[case_num] IN tbl)
作为PowerBI的新手,我曾被这个问题困扰过。我想创建一个自定义度量,可以使用 SQL 语句轻松解决,如下所示:
select count(*) from Task
where case_num in(
select case_num from Task
where task_type="DDD") sub
有人可以帮我解决这个问题吗?谢谢!!!!!
The table is roughly like this
试试这个措施
_count =
CALCULATE ( COUNT ( Task[CaseNum] ), FILTER ( Task, Task[task_type] = "DDD" ) )
Edit
如果您想在过滤器中使用少量任务,可以使用此
Measure =
CALCULATE ( COUNT ( Task[Case] ), FILTER ( Task, Task[task_type] IN {"BB","AA","DDD","CC"}))
如果您不想在过滤器中手动输入大量任务,请先创建一个查找 table 并在度量中使用它
TaskLookUpTable = DATATABLE ( --a long list of task; hence taskTbl
"task_type", STRING,
{
{ "BB"},
{ "AA"},
{ "DDD"},
{ "CC"}
}
)
Measure2 = --create the above table first before writing this measure
CALCULATE (
COUNT ( Task[Case] ),
TREATAS ( VALUES ( 'TaskLookUp'[task_type] ), Task[task_type] )
)
您可以隔离具有特定任务类型的 case_nums
VAR tbl = CALCULATETABLE(VALUES('Table'[case_num]),'Table'[task_type] = "DDD")
然后应用 table 作为过滤器:
Measure =
VAR tbl = CALCULATETABLE(VALUES('Table'[case_num]),'Table'[task_type] = "DDD")
RETURN CALCULATE(COUNT('Table'[case_num]), TREATAS(tbl,'Table'[case_num]))
或
Measure =
VAR tbl = CALCULATETABLE(VALUES('Table'[case_num]),'Table'[task_type] = "DDD")
RETURN CALCULATE(COUNT('Table'[case_num]), 'Table'[case_num] IN tbl)