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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Richard_U
Regular Visitor

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
Employee
Employee

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.

mahoneypat
Employee
Employee

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


Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors