Forum Discussion

arashaga's avatar
arashaga
Icon for Helper I rankHelper I
7 years ago
Solved

Return a vlaue from another column by condition

I have a column Major and I have another calculation called Filter Condition that checks to see if two of the slicers have checked before showing the values on the chart. I would like to use DAX to return the Major when the Filter Condition = "Yes" otherwise return a blank string. For example:

 

Value = If([Filter Condition]="Yes", myTable[Major], "") 

But DAX does not allow me to use myTable[Major] in there and I can only return a measure or calculation. How else I can acheive the same result?

7 Replies

  • AlB's avatar
    AlB
    Icon for Community Champion rankCommunity Champion

    Hi  arashaga

     

    Is Value a measure? If so, you cannot use a naked column like myTable[Major] directly because there is no row context and therefore DAX does not know what value in myTable[Major] to choose.

     

    Maybe if you place myTable[Major] in the rows of a matrix visual and use [Filter Condition]  as a visual level filter, showing the items with value Yes you'll get what you want? (I'm not sure I've completely understood your requirement).

    • arashaga's avatar
      arashaga
      Icon for Helper I rankHelper I

      Thanks AlB, I think all I need is to know how to return a value of a colum row by row within an if condition. Is there anyway we could do this. As an exmaple(pseudo code):

       

      If ( condition is met, myTable[Major], "")
      • AlB's avatar
        AlB
        Icon for Community Champion rankCommunity Champion

        arashaga

         

        Your initial code should be fine for that, if you are using it in a calculated column of myTable and everything in your code refers to myTable.