Forum Discussion

nguyenk172's avatar
nguyenk172
New Member
4 years ago
Solved

Problem with Using SWITCH Function

I am trying to use switch to solve multiple IF statement. But this DAX formula gives me errror as shown below:  Function 'SWITCH' does not support comparing values of type True/False with values of ...
  • v-luwang-msft's avatar
    4 years ago

    Hi nguyenk172 ,

    The formula you are using needs to be split and cannot be equal to one data and then directly equal to another value.

     

    Refer the following sample ,as you provided:

    Type1 = 
    SWITCH (
        TRUE (),
        ISBLANK ( PurchaseOrders[Agreement_KONNR] )
            && PurchaseOrders[CreatedBy_ERNAM] = "BATCHJOB",
            "UC4BATCH"
                && PurchaseOrders[DocumentType_BSART] = "ZB",
        "Z1", "SPA",
      
        "Spot PO"
    )

    Get:

     

    And after adjust:

    Type =
    SWITCH (
        TRUE (),
        ISBLANK ( PurchaseOrders[Agreement_KONNR] )
            && ( PurchaseOrders[CreatedBy_ERNAM] = "BATCHJOB"
            || PurchaseOrders[CreatedBy_ERNAM] = "UC4BATCH" )
            && ( PurchaseOrders[DocumentType_BSART] = "ZB"
            || PurchaseOrders[DocumentType_BSART] = "Z1" ), "SPA",
        "Spot PO"
    )

    Output:

    And according your provided data,you need to adjust to the below:

    Type1 = 
    SWITCH (
        TRUE (),
        ISBLANK ( PurchaseOrders[Agreement_KONNR] )
            && (PurchaseOrders[CreatedBy_ERNAM] = "BATCHJOB"||PurchaseOrders[CreatedBy_ERNAM] = "UC4BATCH"
            )
                && (PurchaseOrders[DocumentType_BSART] = "ZB"||PurchaseOrders[DocumentType_BSART]= "Z1")
        , "SPA",
        NOT ISBLANK ( PurchaseOrders[Agreement_KONNR] )
            && (PurchaseOrders[CreatedBy_ERNAM] = "BATCHJOB"||PurchaseOrders[CreatedBy_ERNAM] = "UC4BATCH"),
        "Auto Calloff",
            NOT ISBLANK ( PurchaseOrders[Agreement_KONNR] )
                && (NOT PurchaseOrders[CreatedBy_ERNAM] = "BATCHJOB"||NOT PurchaseOrders[CreatedBy_ERNAM] = "UC4BATCH"),
        "Buyer Intervention",
        "Spot PO"
    )

    Did I answer your question? Mark my post as a solution!


    Best Regards

    Lucien