Forum Discussion
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
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
- AbhinavJoshiResponsive 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!
- parry2kSuper User
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! ❤️
- MJBLACKNew 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
- parry2kSuper User
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! ❤️
- MJBLACKNew Member
Hi parry2K
Here is the column I created:
Here are the results of the formula. It always returns false.
Thank you
- MJBLACKNew 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
- parry2kSuper User
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! ❤️