I feel like this has to have a really simple solution that I'm overlooking, but I just can't figure it out. I'm looking for a way to count how many times a letter occurs in a string; for example, "animal" would return "2", if I was counting the letter A.
I got it:
Here's the code to copy:
CountIf(Split(TEXT_FIELD, ""), Len(Value(ThisRecord.Value)) > 0)
Here's what it does:
1. The TEXT_FIELD that you want to search for numbers is split by each character
2. Each record's value (in this case, every character) is converted into a number
a. If it's already a number, this will return the character
b. If it's any character other than a number, it will be a blank record
3. The length of each character as a value is checked. If it's a number, this will return a 1. If it was another character that is now a blank record, this will return a 0.
4. Every 1 in this list is counted, returning you the number of numbers in your text field
My explanation might be a little confusing, but if you plug in the Split code into a list box it will help it make sense.
Would you be able to solve for the number counts as well? Wondering if there is an eaiser way.
What I did was to use the total length of the string minus the number of dashes your code found.
Ah, I see now that I did the result backwards lol. Glad you got the answer!
Thanks for the help. I need the numbers - not the dashes - but I figured out with your help. Thanks again.
Something like this may work for that:
What if I wanted to just count the numbers in a text field? For example - phone number is 123-456-7890. I want the count of the numbers, not the dashes.
I like your way better, there's less code to reference it later on. Thanks!
@cmitchener This code will give the result seen below,
ClearCollect(colCharacterCount,
DropColumns(
AddColumns(
GroupBy(
Split("animal", ""),
"Value",
"GroupedValues"
)
,
"Count", CountRows(GroupedValues)
), "GroupedValues"
)
)
Please remember to give a 👍 and accept my solution as it will help others in the future.
I figured a solution out, and since I haven't seen a great resource on it yet here's what I've found:
WarrenBelz
146,743
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,079
Most Valuable Professional