cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Richard_U
New Member

Power query to return records between two strings (A-Z, P-W, E-H)

I need to load records from another excel file into another based on a range of characters.

The user can enter the first and last into two cells with corrosponding ranges(firstone, lastone)

From these two values, I need to do a power query to load in the data where the customer name is in between these two values.

So, if I have values 0 and D I would want all the customers who's names started with a number, or A, B, C, or D.  

I am BRAND NEW to power query and haven't been able to figure this out yet. 

2 ACCEPTED SOLUTIONS
mahoneypat
Super User
Super User

Here is one example on how to do this.  You can make two parameters in the query editor called FirstLetter and SecondLetter (note these will be case sensitive), and then add a custom column to your query called Keep with this formula.  It makes the list of letters between your two parameters and checks if the first letter falls within that range.  You then just filter out the "N" columns.

 

= if List.Contains({FirstLetter..SecondLetter}, Text.Start([LastName],1)) then "Y" else "N"

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

v-yingjl
Community Support
Community Support

Hi @Richard_U ,

As @ mahoneypat's mentioned,  you can create two parameters to store your first value and last value, but you can add a query directly like this to filter the column instead of creating a custom column to filter it and remove this column

= Table.SelectRows(#"Changed Type", each List.Contains({firstone..lastone},Text.Start([Name],1)))

 

In addition, when you create parameters, the type of them should better be text if you want to filter 0..D results, otherwise the query would get type convertion error.

paremeter.pngre.png

 

Attached a sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @Richard_U ,

As @ mahoneypat's mentioned,  you can create two parameters to store your first value and last value, but you can add a query directly like this to filter the column instead of creating a custom column to filter it and remove this column

= Table.SelectRows(#"Changed Type", each List.Contains({firstone..lastone},Text.Start([Name],1)))

 

In addition, when you create parameters, the type of them should better be text if you want to filter 0..D results, otherwise the query would get type convertion error.

paremeter.pngre.png

 

Attached a sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

mahoneypat
Super User
Super User

Here is one example on how to do this.  You can make two parameters in the query editor called FirstLetter and SecondLetter (note these will be case sensitive), and then add a custom column to your query called Keep with this formula.  It makes the list of letters between your two parameters and checks if the first letter falls within that range.  You then just filter out the "N" columns.

 

= if List.Contains({FirstLetter..SecondLetter}, Text.Start([LastName],1)) then "Y" else "N"

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors