Forum Discussion

MJBLACK's avatar
MJBLACK
New Member
3 years ago
Solved

filter on a text field

Hello,

 

I have a simple table that includes a column named "purchunit." I want to iterate through the rows and determine if this field has a value of "LB" or "CS".  I thought the following measure (PriceUOM) would work, but it always returns false. Below is a screen shot of my measure and the table

 

Any ideas? 

Thank you

 

PriceUOM =
IF(UPPER(MAX(purchline[PurchUnit]))="LB","true","false")

 

 

 

  • MJBLACK when you add a column it is always in the row context, so add a column, and don't use any aggregate function, did you try what I provided?

     

    👉 Learn Power BI and Fabric - subscribe to our YT channel - @PowerBIHowTo

    If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤️

7 Replies

  • AbhinavJoshi's avatar
    AbhinavJoshi
    Responsive Resident

    Hello MJBLACK. You can achieve this through conditional column in Power Query M. Please see the sceenshot and code attached. 

    = Table.AddColumn(#"Changed Type", "PriceUOM", each if [PurchUnit] = "LB" then true else if [PurchUnit] = "CS" then true else false)

     

    I hope it helps!

     

  • MJBLACK I would recommend using PQ to add a new column but if you want to use DAX for whatever reason then do this:

     

    PriceUOM Column = 
    IF ( purchLine[PurchUnit] = "LB", "true", "false" )

     

    👉 Learn Power BI and Fabric - subscribe to our YT channel - @PowerBIHowTo

    If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤️

    • MJBLACK's avatar
      MJBLACK
      New Member

      Hello,

      If this is a column, how does DAX know what the row context is?  It appears to yield the same result as what I tried to do.

      Thanks

  • MJBLACK when you add a column it is always in the row context, so add a column, and don't use any aggregate function, did you try what I provided?

     

    👉 Learn Power BI and Fabric - subscribe to our YT channel - @PowerBIHowTo

    If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤️

    • MJBLACK's avatar
      MJBLACK
      New Member

      Hi parry2K

      Here is the column I created:

       

      Here are the results of the formula. It always returns false.

       

      Thank you

      • MJBLACK's avatar
        MJBLACK
        New Member

        It appears that your solution does in fact work properly. I converted to upper and the following worked.  

        PriceUOM Column = if(upper(purchline[PurchUnit]) = "LB","true","false")
         
        I will do some more testing and will flag as resolved.
        thanks
         
  • MJBLACK sounds good. 

     

    👉 Learn Power BI and Fabric - subscribe to our YT channel - @PowerBIHowTo

    If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤️