Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

var & condition

Dear 

 

i am using the condition like:

     

IF(
VendorDocumentRegister[Rev Lev]="A1"
|| VendorDocumentRegister[Rev Lev]="A2"
|| VendorDocumentRegister[Rev Lev]="A3"
|| VendorDocumentRegister[Rev Lev]="A4"
|| VendorDocumentRegister[Rev Lev]="A5"
|| VendorDocumentRegister[Rev Lev]="A6"
|| VendorDocumentRegister[Rev Lev]="A7"
|| VendorDocumentRegister[Rev Lev]="A8"
|| VendorDocumentRegister[Rev Lev]="A9"
|| VendorDocumentRegister[Rev Lev]="A10"
and more ....
 
the same above condition is being repeated multiple times on several places
 
is there any to put above condition to var(or any) so that  i can call/use that var(or any) directly instead of typing  above condition again

 

  • Hi, Anonymous ;

    This cannot be separated because your var a returns True if the condition is met; Return False if the condition is not met;
    Then you use if so the type and result of a and being True/False is not a text type. So you can't compare.

     

    So you could change it as :

    condition =
    IF (
        VendorDocumentRegister[Rev Lev] = "A1"
            || VendorDocumentRegister[Rev Lev] = "A2"
            || VendorDocumentRegister[Rev Lev] = "A3"
            || VendorDocumentRegister[Rev Lev] = "A4"
            || VendorDocumentRegister[Rev Lev] = "A5"
            || VendorDocumentRegister[Rev Lev] = "A6"
            || VendorDocumentRegister[Rev Lev] = "A7"
            || VendorDocumentRegister[Rev Lev] = "A8",
        "This is A series",
        "no"
    )
    

    Or 

    condition =
    IF (
        VendorDocumentRegister[Rev Lev]
            IN { "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8" },
        "This is A series",
        "no"
    )
    

     Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Hello there Anonymous ! If I understood your question correctly, you can use a SWITCH() function to accomplish what you need:

    Measure_switch = SWITCH( 
    SELECTEDVALUE( Table[Column_with_condition]),
    "first_condition", first result,
    "second_condition", second result,
    else_result)

    Hope this answer solves your problem!
    If you need any additional help please @ me in your reply.
    If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
    Thanks!

    You can also check out my LinkedIn!

    Best regards,
    Gonçalo Geraldes

    • Anonymous's avatar
      Anonymous
      Not applicable

      Dear Sir

       

      Thats not answer what i am looking for, i think you did not understand my question

      whether condition switch if or switch

      My same (with lot of and or or )condition is being repeating on multiple place so that i need to put that condition to variable or function so that i can use by calling that var/function

      example:

           var a=                        

                       " VendorDocumentRegister[Rev Lev]="A1"
                       || VendorDocumentRegister[Rev Lev]="A2"
                       || VendorDocumentRegister[Rev Lev]="A3"
                       || VendorDocumentRegister[Rev Lev]="A4"
                       || VendorDocumentRegister[Rev Lev]="A5"
                       || VendorDocumentRegister[Rev Lev]="A6"
                       || VendorDocumentRegister[Rev Lev]="A7"
                       || VendorDocumentRegister[Rev Lev]="A8" "
      return
      if(a,"This is A series","no")
       
       
      but error occured: Cannot convert value 'VendorDocumentRegister[Rev Lev]='A1'' of type Text to type True/False.
       
      ??
      • goncalogeraldes's avatar
        goncalogeraldes
        Icon for Super User rankSuper User

        Anonymous what about this?

         

        Series =
        IF ( LEFT ( VendorDocumentRegister[Rev Lev], 1 ) = "A", "This is A series", "no" )

         

        Hope this answer solves your problem!
        If you need any additional help please @ me in your reply.
        If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
        Thanks!

        You can also check out my LinkedIn!

        Best regards,
        Gonçalo Geraldes

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, Anonymous ;

    This cannot be separated because your var a returns True if the condition is met; Return False if the condition is not met;
    Then you use if so the type and result of a and being True/False is not a text type. So you can't compare.

     

    So you could change it as :

    condition =
    IF (
        VendorDocumentRegister[Rev Lev] = "A1"
            || VendorDocumentRegister[Rev Lev] = "A2"
            || VendorDocumentRegister[Rev Lev] = "A3"
            || VendorDocumentRegister[Rev Lev] = "A4"
            || VendorDocumentRegister[Rev Lev] = "A5"
            || VendorDocumentRegister[Rev Lev] = "A6"
            || VendorDocumentRegister[Rev Lev] = "A7"
            || VendorDocumentRegister[Rev Lev] = "A8",
        "This is A series",
        "no"
    )
    

    Or 

    condition =
    IF (
        VendorDocumentRegister[Rev Lev]
            IN { "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8" },
        "This is A series",
        "no"
    )
    

     Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.