我有一个来自 excel 的公式,我想将其转换为 DAX,我需要它作为 powerbi 的测量或功率查询作为 M
excel的公式为:
=IF(IF(G2=1;COUNTIFS(O:O;O2;C:C;">="&C2;C:C;"<="&C2+1;M:M;">"&M2);0)>0;1;0)
地点: G是列放弃, O是专栏客户, C 是列日期, M 是 DateTime 列
如果第一个是:
IF(G2=1;COUNTIFS(O:O;O2;C:C;">="&C2;C:C;"<="&C2+1;M:M;">"&M2);0)
这被用作第二个条件,如果是:
=IF("if1">0;1;0)
问题缺少样本数据和期望的输出,因此难以理解和回答。
在极不可能的情况下这会有所帮助,您可以在 powerquery 中执行此操作
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"C", type date}, {"M", type datetime}}),
#"Added Custom" = Table.AddColumn(#"Changed Type","dM",(x)=>Table.RowCount(Table.SelectRows(#"Changed Type", each [O]=x[O] and [C]>=x[C] and [C]<=Date.AddDays(x[C],1) and [M]>x[M]) )),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each try if [G]=1 and [dM]>0 then 1 else 0 otherwise null),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"dM"})
in #"Removed Columns"
G | O | C | 男 |
---|---|---|---|
1 | aaa | 01/10/2020 | 01/10/20 12:30:00 |
1 | bb | 01/10/2020 | 01/10/20 13:30:00 |
1 | aaa | 01/10/2020 | 01/10/20 14:30:00 |
0 | bb | 01/10/2020 | 01/10/20 12:30:00 |
0 | aaa | 01/10/2020 | 01/10/20 13:30:00 |
0 | bb | 01/10/2020 | 01/10/20 14:30:00 |
1 | aaa | 01/11/2020 | 01/11/20 12:30:00 |
1 | bb | 01/11/2020 | 01/11/20 13:30:00 |
1 | aaa | 01/11/2020 | 01/11/20 14:30:00 |
0 | bb | 01/11/2020 | 01/11/20 12:30:00 |
0 | aaa | 01/11/2020 | 01/11/20 13:30:00 |
0 | bb | 01/11/2020 | 01/11/20 14:30:00 |
并得到