根据 DAX Power BI 中的特定条件过滤掉字符串和数字
Filter out string and numbers based on certain condition in DAX Power BI
我有我的数据-
sl.no
category
quantity
1
yes
13
2
no
unanswered
3
no
10
4
yes
15
5
no
17
6
no
unanswered
7
no
9
8
yes
0
现在我想在它应该在的位置创建一个新列 (#quant) - 如果类别列中的数字大于 15,则应为“>15”,如果小于等于 15,则为“<= 15”,如果为 0 则为“0”,未回答的应保持原样。所以我的最终输出将是 -
sl.no category quantity #quant(newly created column)
1 yes 13 <=15
2 no unanswered unanswered
3 no 10 <=15
4 yes 15 <=15
5 no 17 >15
6 no unanswered unanswered
7 no 9 <=15
8 yes 0 0
请帮我得到想要的输出
您可以使用此公式添加 custom column
if ([quantity] = "unanswered" or [quantity] = "0") then
[quantity]
else
try
if Int32.From([quantity]) > 15 then ">15"
else "<=15"
otherwise "not a number"
像这样
这会给你预期的结果:
它会检查 quantity
是 unanswered
还是 0
并且在这种情况下保持不变。否则,它将尝试将该值转换为整数并检查它是否大于 15。如果它不是数字,它将 return not a number
.
如果你想把它作为 dax 列。
#quant(newly created column) =
IFERROR (
SWITCH (
TRUE (),
VALUE ( 'Table (2)'[quantity] ) = 0, "0",
VALUE ( 'Table (2)'[quantity] ) > 15, ">15",
VALUE ( 'Table (2)'[quantity] ) <= 15, "<=15"
),
'Table (2)'[quantity]
)
这只接受包含可以转换为值的字符串的单元格。如果那不可能,它 returns 单元格内容。
我有我的数据-
sl.no | category | quantity |
---|---|---|
1 | yes | 13 |
2 | no | unanswered |
3 | no | 10 |
4 | yes | 15 |
5 | no | 17 |
6 | no | unanswered |
7 | no | 9 |
8 | yes | 0 |
现在我想在它应该在的位置创建一个新列 (#quant) - 如果类别列中的数字大于 15,则应为“>15”,如果小于等于 15,则为“<= 15”,如果为 0 则为“0”,未回答的应保持原样。所以我的最终输出将是 -
sl.no category quantity #quant(newly created column)
1 yes 13 <=15
2 no unanswered unanswered
3 no 10 <=15
4 yes 15 <=15
5 no 17 >15
6 no unanswered unanswered
7 no 9 <=15
8 yes 0 0
请帮我得到想要的输出
您可以使用此公式添加 custom column
if ([quantity] = "unanswered" or [quantity] = "0") then
[quantity]
else
try
if Int32.From([quantity]) > 15 then ">15"
else "<=15"
otherwise "not a number"
像这样
这会给你预期的结果:
它会检查 quantity
是 unanswered
还是 0
并且在这种情况下保持不变。否则,它将尝试将该值转换为整数并检查它是否大于 15。如果它不是数字,它将 return not a number
.
如果你想把它作为 dax 列。
#quant(newly created column) =
IFERROR (
SWITCH (
TRUE (),
VALUE ( 'Table (2)'[quantity] ) = 0, "0",
VALUE ( 'Table (2)'[quantity] ) > 15, ">15",
VALUE ( 'Table (2)'[quantity] ) <= 15, "<=15"
),
'Table (2)'[quantity]
)
这只接受包含可以转换为值的字符串的单元格。如果那不可能,它 returns 单元格内容。