如何将Tableau中的ifnull语句转换为powerbi dax?

时间:2019-06-07 09:41:10

标签: if-statement powerbi tableau dax ifnull

我正在将仪表板从Tableau转换为Power Bi,并将计算出的尺寸卡在Tableau中,需要使用dax将其转换为Powerbi!

通过替换tableau中的IFNULL语句。我已经尝试使用IF语句在dax中使用ISBLANK参数,该语句应检查该字段是否返回空值。我对dax的了解有限,我想这个问题确实很简单,但是我坚持了好几个小时。

需要转换为powerbi的Tableau代码:

if LEFT([Supplier Code],1) = "E" then "Employees Claims" else 
IF 
IFNULL(IFNULL([ASL Supplier (SWPS)],IFNULL([Supplier Name],IFNULL([Vendor],[Supplier Code]))),'Not Define')= 'N/A'
THEN IFNULL([Vendor],[Supplier Name]) ELSE
IFNULL(IFNULL([ASL Supplier (SWPS)],IFNULL([Supplier Name],IFNULL([Vendor],[Supplier Code]))),'Not Define') 
END
END

我尝试过的Power bi代码:

Supplier (swps) = IF(LEFT([Supplier Code],1) = "E", "Employee Claims",
IF(
IF(ISBLANK(V_FIPnLDashboard_Tne[ASL Supplier (SWPS)]),ISBLANK(V_FIPnLDashboard_Tne[Supplier Name]),ISBLANK(V_FIPnLDashboard_Tne[Supplier Code])),"Not Define") = "N/A")

我的代码不完整,因为我无法理解Tableau中代码的完整分解。

表格:

if LEFT([Supplier Code],1) = "E" then "Employees Claims" else 
IF 
IFNULL(IFNULL([ASL Supplier (SWPS)],IFNULL([Supplier Name],IFNULL([Vendor],[Supplier Code]))),'Not Define')= 'N/A'
THEN IFNULL([Vendor],[Supplier Name]) ELSE
IFNULL(IFNULL([ASL Supplier (SWPS)],IFNULL([Supplier Name],IFNULL([Vendor],[Supplier Code]))),'Not Define') 
END
END

预期结果是一个尺寸/列,其值等于幂bi中的给定条件。

3 个答案:

答案 0 :(得分:0)

在您的示例中,我发现分解Tableau代码的原始逻辑最有用:

  • 如果供应商代码以“ E”开头,则为“员工索偿”
  • 其他,
    • 按顺序检查ASL供应商(SWPS),供应商名称,供应商,供应商代码=“ N / A”,则
      • 如果供应商不为空,则供应商
      • 其他,供应商名称
    • 否则,按顺序检查,
      • 如果ASL供应商(SWPS),供应商名称,供应商,供应商代码具有值,请使用
      • 否则,请使用“未定义”

鉴于此,DAX公式为:

Supplier (swps) =
VAR vendorOrSupplier =
    IF (
        ISBLANK ( V_FIPnLDashboard_Tne[Vendor] ),
        V_FIPnLDashboard_Tne[Supplier Name],
        V_FIPnLDashboard_Tne[Vendor]
    )
VAR firstValidField =
    IF (
        ISBLANK ( V_FIPnLDashboard_Tne[ASL Supplier (SWPS)] ),
        IF (
            ISBLANK ( V_FIPnLDashboard_Tne[Supplier Name] ),
            IF (
                ISBLANK ( V_FIPnLDashboard_Tne[Vendor] ),
                IF (
                    ISBLANK ( V_FIPnLDashboard_Tne[Supplier Code] ),
                    "Not Defined",
                    V_FIPnLDashboard_Tne[Supplier Code]
                ),
                V_FIPnLDashboard_Tne[Vendor]
            ),
            V_FIPnLDashboard_Tne[Supplier Name]
        ),
        V_FIPnLDashboard_Tne[ASL Supplier (SWPS)]
    )
VAR allBlank =
    IF ( firstValidField = "Not Defined", TRUE (), FALSE () )
RETURN
    IF (
        LEFT ( V_FIPnLDashboard_Tne[Supplier Code], 1 ) = "E",
        "Employee Claims",
        IF (
            V_FIPnLDashboard_Tne[ASL Supplier (SWPS)] = "N/A",
            vendorOrSupplier,
            IF (
                ISBLANK ( V_FIPnLDashboard_Tne[ASL Supplier (SWPS)] ),
                IF (
                    V_FIPnLDashboard_Tne[Supplier Name] = "N/A",
                    vendorOrSupplier,
                    IF (
                        ISBLANK ( V_FIPnLDashboard_Tne[Supplier Name] ),
                        IF (
                            V_FIPnLDashboard_Tne[Vendor] = "N/A",
                            vendorOrSupplier,
                            IF (
                                ISBLANK ( V_FIPnLDashboard_Tne[Vendor] ),
                                IF ( [Supplier Code] = "N/A", vendorOrSupplier, firstValidField ),
                                firstValidField
                            )
                        ),
                        firstValidField
                    )
                ),
                firstValidField
            )
        )
    )

答案 1 :(得分:0)

IF IFNULL([ASL Supplier(SWPS)],IFNULL([Supplier(SWPS)],IFNULL([Vendor],IFNULL([Supplier Code],'Not Define')))) = 'N/A'
THEN [Supplier(SWPS)] 
ELSE IFNULL([ASL Supplier (SWPS)],IFNULL([Supplier(SWPS)],IFNULL([Vendor],IFNULL([Supplier Code],'Not Define'))))
END

答案 2 :(得分:0)

supplier = var supplierswps = 
 `IF (
                              ISBLANK (V_FIPnLDashboard_Tne[ASL Supplier(SWPS)]),
        IF (
             ISBLANK (V_FIPnLDashboard_Tne [Supplier (SWPS)]),
            IF (
                ISBLANK ( V_FIPnLDashboard_Tne[Vendor] ),
                IF (
                    ISBLANK (V_FIPnLDashboard_Tne [Supplier Code]),"Not Define")))= "N/A",V_FIPnLDashboard_Tne[Supplier (swps)])
var supplierswpsfalse = IF(supplierswps = "Not define", TRUE(), FALSE())
        return
            if( 
               ISBLANK(V_FIPnLDashboard_Tne[ASL Supplier (SWPS)] ),
                IF (
                    ISBLANK (V_FIPnLDashboard_Tne[Supplier (SWPS)]),
                     IF(
                        ISBLANK ( V_FIPnLDashboard_Tne[Vendor] ),
                            IF (
                                ISBLANK (V_FIPnLDashboard_Tne[Supplier Code] )
                            ,"Not Define",
                            V_FIPnLDashboard_Tne[Supplier Code]
                                ),
`

                       V_FIPnLDashboard_Tne[Vendor]  

                     ),V_FIPnLDashboard_Tne[Supplier (SWPS)]
                ),V_FIPnLDashboard_TnE[ASL Supplier (SWPS)]
            )