Forum Discussion

baruojha's avatar
baruojha
New Member
3 years ago
Solved

Error when using && Containsstring

Want a conditional colum when text in one column is "Others" and another column constans text strings , if both conditions are met the value in new column has to be "API" else "Others", however not successful to write correct statement and getting different errors: Can somebody guide where i am going wrong.

 

Revised Nature = SWITCH(TRUE(),

'Export (3)'[Nature Description]="Others"&& format(CONTAINSSTRING('Export (3)'[Name of the Product] , {"working Standard*","w.std*","wstd"}) ,"True/False")="True","API",


"Others")

 Error : A table to multiple values was supplied where a single value was expected.

  • Hi baruojha ,

    You can't use the symbol {} to represent a list in DAX, and CONTAINSSTRING function already returns true or false, don't need to format it .

    Here's my solution, create a calculated column.

    evised Nature =
    SWITCH (
        TRUE (),
        'Export (3)'[Nature Description] = "Others"
            && (
                CONTAINSSTRING ( 'Export (3)'[Name of the Product], "working Standard*" )
                    || CONTAINSSTRING ( 'Export (3)'[Name of the Product], "w.std*" )
                    || CONTAINSSTRING ( 'Export (3)'[Name of the Product], "wstd" )
            ), "API",
        "Others"
    )
    

    Get the correct result.

    I attach my sample below for your reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • lukiz84's avatar
    lukiz84
    Memorable Member

    The error is because you pass a table ( {"working Standard*, ...} ) to containsstring, that's not possible.

  • Hi baruojha ,

    You can't use the symbol {} to represent a list in DAX, and CONTAINSSTRING function already returns true or false, don't need to format it .

    Here's my solution, create a calculated column.

    evised Nature =
    SWITCH (
        TRUE (),
        'Export (3)'[Nature Description] = "Others"
            && (
                CONTAINSSTRING ( 'Export (3)'[Name of the Product], "working Standard*" )
                    || CONTAINSSTRING ( 'Export (3)'[Name of the Product], "w.std*" )
                    || CONTAINSSTRING ( 'Export (3)'[Name of the Product], "wstd" )
            ), "API",
        "Others"
    )
    

    Get the correct result.

    I attach my sample below for your reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.