DAX Switch Logic转换为TSQL

时间:2017-11-17 23:29:42

标签: sql-server tsql switch-statement dax

如何在TSQL中执行以下DAX表达式?

Channel Mapping: =
     SWITCH(
        TRUE (),
           NOT ( ISERROR ( SEARCH ( "ChannelOne", ChannelFact[ChannelName] ) ) ), "C1",
           NOT ( ISERROR ( SEARCH ( "ChannelTwo", ChannelFact[ChannelName] ) ) ), "C2",
           NOT ( ISERROR ( SEARCH ( "Channel2", ChannelFact[ChannelName] ) ) ), "C2",

        "Not Mapped"
)

我认为它需要CASE逻辑,但不确定如何组合。

1 个答案:

答案 0 :(得分:1)

SELECT CASE ChannelName WHEN "ChannelOne" THEN "C1"
                        WHEN "ChannelTwo" THEN "C2"
                        WHEN "Channel2" THEN "C2"
                ELSE "Not Mapped" END AS "Channel Mapping"
FROM
ChannelFact

感谢。