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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jeffreyjar
Helper II
Helper II

Filter the fifth and the sixth character of a code

Hello everyone, 

 

I have a code like this    A10199015 

 

I want to filter the fifth and the sixth character of the code (or 99) in a table with power query

 

this is the sample data below

A10101001
A10199015
A10399001
B29901001

 

this the filtered table that i want (without a code that have 9(fifth character) and a 9(sixth character))

 

A10101001
B29901001

 

@ryan_mayu 

 

9 REPLIES 9
ryan_mayu
Super User
Super User

@Jeffreyjar 

you can try to create a new column in PQ

=Text.Middle([column],4,2)="99"

1.PNG

 

then filter the custom column

2.PNG

 

at last, delete the custom column

3.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Jeffreyjar
Helper II
Helper II

Jeffreyjar_0-1663822800509.png

getting now this error

 

@rsbin 

 

can i send you the .pbix file through mail?

@Jeffreyjar ,

Good Morning.

You can attach your pbix file to your reply message. Below the reply box is where you can attach your file.

Jeffreyjar_0-1663855840107.png

 

Jeffreyjar
Helper II
Helper II

Jeffreyjar_0-1663787886158.png

hello @rsbin 

it is giving me this error 

@Jeffreyjar ,

let
    Source = YOURSOURCE
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Agents", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "5th&6th", each Text.Middle( [Agents],4, 2 ))
in
    #"Added Custom"

rsbin_0-1663788316358.png

Both Agents and your new column should be text.  I cannot tell what is causing that error.  Works for me just fine.

Jeffreyjar
Helper II
Helper II

hello @rsbin 

thanks for the tip, but can you do it with a  specific column for example Agents

@Jeffreyjar ,

When you are in Power Query, goto the last step of your Applied Steps.

Select the Add Column menu at the top and select Custom Column

rsbin_0-1663787344463.png

In the Dialogue Box, type the following:

Text.Middle([Agents],4,2 ) 

If there are no syntax errors, click OK.

rsbin
Super User
Super User

@Jeffreyjar ,

As a new step in Power Query, Add a Custom Column that extracts the fifth and sixth characters:

= Table.AddColumn(#"Changed Type", "5th&6th", each Text.Middle([code],4,2 ))

  Then simply filter that column by excluding "99".

Others here may be able to do it in one step, but for clarity, my preference would be the two step approach to ensure you are excluding the correct records.

Regards,

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.