'Tricky filtering data

In a Power App, I'm looking to filter a gallery with Dataverse table data by a Location column. Examples of Locations are as follows: L.1.1.1A, L.2.5.3B, L.9.1.12C, L.10.3.2A

I want to filter where the Location begins where the second number (the character after the second period) is a 1 or a 2. If the character I was looking at was at the beginning or the end, I know I could use StartsWith or EndsWith (as shown below), but I don't know how I can solve for this situation where the value is in the middle of the string.

Filter('DataTable',Or(StartsWith(Location,"L.1"),StartsWith(Location,"L.2")))


Solution 1:[1]

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-find

First, find the position of the second period. Let’s say we name this PosDot2

Now you can take a substring by using for example:

Right( Len( Location.Data) - PosDot2 )

EDIT:

In order to explain a bit more: L.1.2.3A is your example.

With the function 'find', you can find your period.

Find(
  ".",
  YourLocation
)

This gives the first location, which we will name P1. P2 can be found via:

Find(
  ".",
  YourLocation,
  P1 + 1

)

Via Mid, you can retrieve everything between the first and second period via:

Mid(
  YourLocation,
  P1 + 1,
  P2 - P1 - 1
)

This gives the subsection.

A demo can be found here on my Github repo, so you can get a feeling of what's happening

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1