[英]Applying advanced filter in Power BI DAX, from a different table
I have the following tables:我有以下表格:
My DAX calculation sums up [Days_epi] unique values, from Episodes tbl, grouping them by [ProgramID_epi], [EpisodeID_epi], [ClientID_epi].我的 DAX 计算总结了来自 Episodes tbl 的 [Days_epi] 唯一值,并按 [ProgramID_epi]、[EpisodeID_epi]、[ClientID_epi] 对它们进行分组。
So, the SUM of [Days_epi] = 3 + 5 + 31 + 8 + 15 + 20 + 10 = 92因此,[Days_epi] 的总和 = 3 + 5 + 31 + 8 + 15 + 20 + 10 = 92
Here is my working code for this:这是我的工作代码:
DaysSUM =
CALCULATE (
SUMX (
SUMMARIZE (
'Episodes',
'Episodes'[EpisodeID_epi],
'Episodes'[ProgramID_epi],
'Episodes'[ClientID_epi],
'Episodes'[Days_epi]
),
'Episodes'[Days_epi]
),
FILTER (
'Episodes',
'Episodes'[Category_epi] = "Homeless"
)
)
I need to add two advanced filters to the calculation above:我需要在上面的计算中添加两个高级过滤器:
Filter 1 should ONLY KEEP records in Episodes, if the records in the Clients have the difference between [DischDate_clnt] and [AdmDate_clnt] >= 365.如果客户端中的记录在 [DischDate_clnt] 和 [AdmDate_clnt] >= 365 之间存在差异,则过滤器 1 应该只保留情节中的记录。
Filter 1 in SQL statement is SQL 语句中的过滤器 1 是
DATEDIFF(DAY, [AdmDate_clnt], [DischDate_clnt]) >= 365)
After that, Filter 2 should ONLY KEEP records in Episodes, if the records in the Clients have [Date_clnt] >= [AdmDate_clnt] + 12 months.之后,过滤器 2 应该只保留情节中的记录,如果客户端中的记录有 [Date_clnt] >= [AdmDate_clnt] + 12 个月。 (12 month after the Admission Date)
(入学日期后12个月)
Filter 2 in SQL statement is SQL 语句中的过滤器 2 为
[Date_clnt] <= DATEADD(MONTH, 12, [[AdmDate_clnt])
So, after applying those two filters I expect the records 6 and 10 of the Episodes tbl must be excluded (filtered out), because the records 2 and 3 of the Clients tbl (highlighted in green) are not satisfied my Filter 1 / Filter 2.因此,在应用这两个过滤器后,我希望 Episodes tbl 的记录 6 和 10 必须被排除(过滤掉),因为 Clients tbl 的记录 2 和 3(以绿色突出显示)不满足我的过滤器 1/过滤器 2 .
Here is the final Episodes dataset I should have (without the 2 records in red):这是我应该拥有的最终剧集数据集(没有红色的 2 条记录):
I was starting to update my DAX code as the following (below).我开始如下更新我的 DAX 代码(如下)。 But keep receiving error "Parameter is not the correct type"
但不断收到错误“参数不是正确的类型”
enter
DaysSUM_Filters =
CALCULATE (
SUMX (
SUMMARIZE (
'Episodes',
'Episodes'[EpisodeID_epi],
'Episodes'[ProgramID_epi],
'Episodes'[ClientID_epi],
'Episodes'[Days_epi]
),
'Episodes'[Days_epi]
),
FILTER (
'Episodes',
'Episodes'[Category_epi] = "Homeless"
), TREATAS(DATEDIFF('Clients'[AdmDate_clnt],
'Clients'[DischDate_clnt], DAY)>=365,
'Clients'[Date_clnt])
)
Not exactly sure how to set those 2 filters correctly in DAX Power BI, as I am relatively new to it.不完全确定如何在 DAX Power BI 中正确设置这两个过滤器,因为我对它比较陌生。
Please help!请帮忙!
I can't say about all the case.我不能说所有的情况。 But what is obvious is that you use
TREATAS
in a wrong way.但显而易见的是,您以错误的方式使用
TREATAS
。 It works like this TREATAS({"Red", "White", "Blue"}, 'Product'[Color])
.它的工作原理类似于
TREATAS({"Red", "White", "Blue"}, 'Product'[Color])
。
In your case在你的情况下
DATEDIFF('Clients'[AdmDate_clnt],
'Clients'[DischDate_clnt], DAY)>=365
will return TRUE
or FALSE
value.将返回
TRUE
或FALSE
值。 The first argument of TREATAS - is a column or set of columns not a single value. TREATAS 的第一个参数 - 是一列或一组列,而不是单个值。
You can use the filter like this:您可以像这样使用过滤器:
FILTER(
'Clients'
,DATEDIFF(
'Clients'[AdmDate_clnt]
,'Clients'[DischDate_clnt]
,DAY
)>=365
)
This will return you a filtered table.这将为您返回一个过滤表。 This may work if your tables are linked.
如果您的表是链接的,这可能会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.