Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
nguyenk172
New Member

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 type Text. Consider using the VALUE or FORMAT function to convert one of the values.
I wonder if anyone knows how to fix this. Much appreciated
 
This my DAX formula
Type =
SWITCH(
True(),
ISBLANK(PurchaseOrders[Agreement_KONNR]) && PurchaseOrders[CreatedBy_ERNAM] ="BATCHJOB","UC4BATCH" && PurchaseOrders[DocumentType_BSART]="ZB","Z1","SPA",
Not ISBLANK(PurchaseOrders[Agreement_KONNR]) && PurchaseOrders[CreatedBy_ERNAM] ="BATCHJOB","UC4BATCH","Auto Calloff",
Not ISBLANK(PurchaseOrders[Agreement_KONNR]) && Not PurchaseOrders[CreatedBy_ERNAM]="BATCHJOB","UC4BATCH","Buyer Intervention",
"Spot PO"
)
 
 
1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

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.

vluwangmsft_0-1646897091050.png

 

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:

vluwangmsft_1-1646897208617.png

 

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:

vluwangmsft_2-1646897246244.png

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"
)

vluwangmsft_3-1646897441331.png

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


Best Regards

Lucien

 

View solution in original post

3 REPLIES 3
v-luwang-msft
Community Support
Community Support

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.

vluwangmsft_0-1646897091050.png

 

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:

vluwangmsft_1-1646897208617.png

 

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:

vluwangmsft_2-1646897246244.png

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"
)

vluwangmsft_3-1646897441331.png

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


Best Regards

Lucien

 

DarrenLau
Advocate I
Advocate I

Hi,

Found your question interesting and I came up with the following. Hope it helps and at the very least, points you to the right direction to get your formula working.

Assign Status = 
VAR _checkAgreement = IF ( MAX ( Purchases[AgreementID] ) = "-", TRUE(),FALSE())
VAR _checkCreated = OR ( MAX (Purchases[CreatedBy])="BATCHJOB", MAX(Purchases[CreatedBy])="UC4BATCH")
VAR _checkDocType = OR ( MAX (Purchases[DocumentType])="Z1", MAX(Purchases[DocumentType])="ZB")
VAR _status = 
    SWITCH(TRUE(),
        _checkAgreement && _checkCreated && _checkDocType, "SPA",
        _checkAgreement = FALSE() && _checkCreated, "Auto Calloff",
        _checkAgreement = FALSE() && _checkCreated = FALSE(),"Buyer Intervention",
        "Spot PO"  
    )
RETURN
    _status

 

Link to example PBIX for reference - SWITCH example 

I had some trouble with the ISBLANK() function so I substituted "-" into the data as a check to save time.

 

Example table and results to check logic:-

DarrenLau_0-1646710778171.png

 

Samarth_18
Community Champion
Community Champion

Hi @nguyenk172 ,

 

Looks some issue in switch conditions, Could you please share the sample data in text format with expected output?

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors