Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
majdkaid22
Helper V
Helper V

a measure formula using "contain" to capture rows including particular letters

Hi,

 

a biggener question here, so bear with me please 🙂

 

I have a reportthat I extract manually from a (stupid) BackOffice system which have all the deposits & withdrawals transactions. 

 

The annoying thing, that there is no ID in the report to tag what is deposit, withdrawal, fees, rebate...etc so as seen below the Column "amount" has all the figures. 

 

on Excel, I came over this, by filtiering the "Comment" column to show only rows that contian (Dep or WDRL) and I remove whatever else. (pretty manual and annoying to re-do everytime, you upload a newer data)

 

I tried writing few Dax formulas to be kinda similar to what I want in power BI, but I failed. 

 

 

Deposit.PNG

 

Could there be any way/formula that I can create a measure or filter rows that only contains part of the word

 

For instance, some of the comments will have (deposit, Dep, DEPMAS, DEPVIS) so if I sucsess by being able to filter or have a measure that can pick up "dep" I can secure that I will have the correct deposits amount. And same I can do for withdrawals. 

 

Thanks in advance,

Majd

2 ACCEPTED SOLUTIONS

That formula you're currently using, use exactly the same thing, but with all instances of [Comment] replaced with Text.Upper( [Comment] ), and make sure you compare to strings that are in all caps.

 

=if Text.Contains( Text.Upper( [Comment] ), "DEP" )
  or Text.Contains( Text.Upper( [Comment] ), "WDRL" )
then "x"
else "-"

This is what was suggested above, but I've formatted a bit nicer with line breaks.

 

Or, even more simply, you can use the following snippet of the above:

=Text.Contains( Text.Upper( [Comment] ), "DEP" )
  or Text.Contains( Text.Upper( [Comment] ), "WDRL" )

The return values will not be "x" and "-", but will instead be Boolean values, true and false. Just as easy to filter on in the report.

 

P.S. Guys, can we please make use of code blocks and share our code in text, so that it's copy-pasteable, rather than depending on people to re-write verbatim the formula you've got in a screen shot?

View solution in original post

Hi @majdkaid22,

 

her comes the baby steps:

 

Before you do the filter operation as mentioned in my answer today, just right click the column Comments, and go to Transform and then upper case (or lower case, if you prefer that). That makes the complete column upper case. Now you can search for dep and wdrl. As @greggyb mentioned M is case sensitive, so you always have to keep that in mind, when you are searching for something.

 

Regards,

Lars

View solution in original post

13 REPLIES 13
Anonymous
Not applicable

Hi,

 

Just want to say thank you @LarsSchreiber and @greggyb! Didn't realize to use Power Query in the editing window. Much appreciated.
Solved my similar issue that I had 🙂

Anonymous
Not applicable

Hi majdkaid22,

 

   like @LarsSchreiber asked you, the values that you are searching in "Comment" are just Dep and WDRL?

Because I have something in mind about using the SEARCH function.

@Anonymous Hi mate,

 

Yes these are the values am looking for (deposits & withdrawals) however they are not the precise words "Dep" & "WDRL"

 

some values could be "Deposit", "Dep", "depVisa" and the criteria should search for (dep) inside the whole narrative and if found to be tagged.

 

Elaborate on your thoughts of SEARCH. I can see it giving a positive result 🙂

 

Majd  

For this, Power Query is definitely the right answer like in @LarsSchreiber's post.

LarsSchreiber
Responsive Resident
Responsive Resident

Hello Majd,

 

one question to your column "Comment". Do you need it in your model only for filtering on "Dep" and "WDRL", or do you need it for more things? I am asking because as far as I can see this column has only unique values and this is very expensive in Power BI. Those columns should be avoided as possible. 

 

If you don't need this column for other things, I recommend you, to go to the query definition of that table and just filter the Comment column, as you can see in the screenshot below:

 

02.jpg

 

Therefore only click on the filter item beside the column header and use "contains". Then ust delete the column Comment. The result is a table that contains only the rows, where the comment column contained Dep or WDRL.

 

If you need the column Comment for more things, i would recommend to create a custom column, which identifies a specific row depending on Dep and WDRL in the Comment column. Take a look at the next screenshot:

 

03.jpg

 

I called that new column Filter. It returns a "x" when the Comment contains an Dep or WDRL, and a "-" if not.

 

Now you can create a simpler DAX statement, relying on that new custom column "Filter", which also shoul be faster, because you are scanning a column, that only has two possible values and not strings with 20 digits and more.

 

I hope that helps,

 

Regards,

Lars

 

@LarsSchreiber much appreciated for the time and the great explanation. 

 

I did what you provided step by step and was able to get the results, however it appears that "contains" is only taking the defined text "dep" or "DEP"

 

below are screenshot of what I have got when I ran it over

 

You can see that columns 1,2,3, weren't tagged, although "DEP" is part of the text, while in other rows where DEP is a full text it has been tagged. 

 

 

DEP.PNG

And when using "Dep" a different Narrative are tagged.

 

iDep1.PNG 

 

 

If we can implement in power BI something similar to text filter in Excel, where "contains" works perfectly 

 

Excel.PNG

 

 

 

And to answert your earlier question, I would only need to caputre the deposits & withdrawals (dep & wdrl)

 

 

Regards,

Majd 

Power Query is case sensitive by default. First cast the entire string to upper case before checking. It is as simple as wrapping the column reference in Text.Upper() in your current formula.

@greggyb Can you elaborate in baby steps?

 

am quite beginner when it comes to power query 🙂

 

 

Cheers,

Majd 

Hi @majdkaid22,

 

her comes the baby steps:

 

Before you do the filter operation as mentioned in my answer today, just right click the column Comments, and go to Transform and then upper case (or lower case, if you prefer that). That makes the complete column upper case. Now you can search for dep and wdrl. As @greggyb mentioned M is case sensitive, so you always have to keep that in mind, when you are searching for something.

 

Regards,

Lars

@LarsSchreiber it all worked out, and I was able to create 3 different measures to represent, Gross/Net deposits and withdrawals. 

 

Many thanks for the details and Patience.

 

 

Cheers,

Majd

That formula you're currently using, use exactly the same thing, but with all instances of [Comment] replaced with Text.Upper( [Comment] ), and make sure you compare to strings that are in all caps.

 

=if Text.Contains( Text.Upper( [Comment] ), "DEP" )
  or Text.Contains( Text.Upper( [Comment] ), "WDRL" )
then "x"
else "-"

This is what was suggested above, but I've formatted a bit nicer with line breaks.

 

Or, even more simply, you can use the following snippet of the above:

=Text.Contains( Text.Upper( [Comment] ), "DEP" )
  or Text.Contains( Text.Upper( [Comment] ), "WDRL" )

The return values will not be "x" and "-", but will instead be Boolean values, true and false. Just as easy to filter on in the report.

 

P.S. Guys, can we please make use of code blocks and share our code in text, so that it's copy-pasteable, rather than depending on people to re-write verbatim the formula you've got in a screen shot?

It has indeed worked. much appreciated mate

Hi @greggyb,

 

I am absolutely with you, when you are requesting code blocks here. But when you are dealing with an absolute beginner, in my opinion it is necessarry to not only show the code, but also the GUI to show how to get there. No newby knows, which button generates which code. But next time, I will just copy the code block below in addition. Thanks for that hint.

 

Regards,

Lars

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors