Forum Discussion

dbehara's avatar
dbehara
Frequent Visitor
5 years ago
Solved

IF and CASE statement

Hi All,

 

Could anyone please help me with below query on power bi, the query im using on tableau

 

IF NOT ISNULL([task id]) THEN (CASE [activity] WHEN 'Yes' THEN 1 ELSE 0 END) ELSE 0 END

 

Thanks for help 🙂

  • Hey dbehara ,

     

    sorry, that was my mistake. You have to use the double quotes.

    Try this one:

    New column =
    SWITCH(
        TRUE(),
        myTable[task id] = BLANK(), 0,
        myTable[activity] = "Yes", 1,
        0
    )

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
     
    Best regards
    Denis
     

6 Replies

  • selimovd's avatar
    selimovd
    Most Valuable Professional

    Hey dbehara ,

     

    what exactly do you want to do? Is that a SQL query? Is that a new calculated column? Should that be a measure?

    I think a little bit more context is required to help you.

     

    Best regards

    Denis

    • dbehara's avatar
      dbehara
      Frequent Visitor

      selimovd Im using above query on tableau and trying to re-create same on power bi

      basically [task id] should not be null, while calculating activity as 'Yes'

       

      Hope i have answered 🙂

      • selimovd's avatar
        selimovd
        Most Valuable Professional

        Hey dbehara ,

         

        Power BI is not Tableau, what is the reason I asked where exactly you need that.

        In this case I can just guess. An approach for a calculated column would be:

        New column =
        SWITCH(
            TRUE(),
            myTable[task id] = BLANK(), 0,
            myTable[activity] = 'Yes', 1,
            0
        )

         

        If you need any help please let me know.
        If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
         
        Best regards
        Denis