Power BI multiple if 包含从 Tableau 计算的度量的拆分转换

Power BI multiple if contains split converting from Tableau calculated measure

我是 Power BI 的新用户,突然从 Tableau 切换过来,但我在使用 DAX 表达式时遇到了一些问题。

我有一列 (Detail1) URL,其中一些(以 .aspx、.ppt、.pdf、.doc 结尾)附加了一些垃圾字符串。在 tableau 中,我根据以下计算创建了一个计算列来清理它们:

    IF CONTAINS([Detail1],".aspx") THEN
        SPLIT([Detail1], ".aspx",1) + ".aspx"
    ELSEIF CONTAINS([Detail1],".ppt") THEN
        SPLIT([Detail1], ".ppt",1) + ".ppt"
    ELSEIF CONTAINS([Detail1],".pdf") THEN
        SPLIT([Detail1], ".pdf",1) + ".pdf"
    ELSEIF CONTAINS([Detail1],".doc") THEN
        SPLIT([Detail1], ".doc",1) + ".doc"
    ELSE
        [Detail1]
    END

但是我在 DAX 表达式中很难做到这一点。谁能指出我正确的方向?

非常感谢您的帮助!

我创建了一个虚拟 table,其中包含带有不需要的额外信息的 URL。 对于您的问题,我有两个 DAX 解决方案。

解决方案 1:DAX

Table

+--------------------------------------+
|                Detail1               |
+--------------------------------------+
| https://url.com/page1.aspx?extrainfo |
+--------------------------------------+
| https://url.com/page1.doc?extrainfo  |
+--------------------------------------+
| https://url.com/page1.ppt?extrainfo  |
+--------------------------------------+
| https://url.com/page1.pdf?extrainfo  |
+--------------------------------------+
| https://url.com/page1.doc?extrainfo  |
+--------------------------------------+

在不知道你的数据的情况下,最简单的解决方案是提取 ? 符号之前的所有内容,我可以想象你的数据集中可能有类似的结构。

如果是这种情况,您可以创建以下计算列

CleanUrl = 
PATHITEMREVERSE(SUBSTITUTE([Detail1],"?","|"),2,TEXT)

正在创建这个table

+--------------------------------------+----------------------------+
|                Detail1               |          CleanUrl          |
+--------------------------------------+----------------------------+
| https://url.com/page1.aspx?extrainfo | https://url.com/page1.aspx |
+--------------------------------------+----------------------------+
| https://url.com/page1.doc?extrainfo  | https://url.com/page1.doc  |
+--------------------------------------+----------------------------+
| https://url.com/page1.ppt?extrainfo  | https://url.com/page1.ppt  |
+--------------------------------------+----------------------------+
| https://url.com/page1.pdf?extrainfo  | https://url.com/page1.pdf  |
+--------------------------------------+----------------------------+
| https://url.com/page1.doc?extrainfo  | https://url.com/page1.doc  |
+--------------------------------------+----------------------------+

解决方案 2:DAX

如果您的列 Detail1 中没有明确的模式,则以下计算列采用相同的逻辑并将其调整为 DAX

CleanUrlV2 =
    SWITCH (
    TRUE (),
    CONTAINSSTRING ( [Detail1], ".aspx" ), PATHITEMREVERSE ( SUBSTITUTE ( [Detail1], ".aspx", "|" ), 2, TEXT ) & ".aspx",
    CONTAINSSTRING ( [Detail1], ".ppt" ), PATHITEMREVERSE ( SUBSTITUTE ( [Detail1], ".ppt", "|" ), 2, TEXT ) & ".ppt",
    CONTAINSSTRING ( [Detail1], ".pdf" ), PATHITEMREVERSE ( SUBSTITUTE ( [Detail1], ".pdf", "|" ), 2, TEXT ) & ".pdf",
    CONTAINSSTRING ( [Detail1], ".doc" ), PATHITEMREVERSE ( SUBSTITUTE ( [Detail1], ".doc", "|" ), 2, TEXT ) & ".doc",
    [Detail1]
)

输出Table

+--------------------------------------+----------------------------+
|                Detail1               |         CleanUrlV2         |
+--------------------------------------+----------------------------+
| https://url.com/page1.aspx?extrainfo | https://url.com/page1.aspx |
+--------------------------------------+----------------------------+
| https://url.com/page1.doc?extrainfo  | https://url.com/page1.doc  |
+--------------------------------------+----------------------------+
| https://url.com/page1.ppt?extrainfo  | https://url.com/page1.ppt  |
+--------------------------------------+----------------------------+
| https://url.com/page1.pdf?extrainfo  | https://url.com/page1.pdf  |
+--------------------------------------+----------------------------+
| https://url.com/page1.doc?extrainfo  | https://url.com/page1.doc  |
+--------------------------------------+----------------------------+

由于某些原因,Whosebug 不支持带有 // 的 Markdown table。