I want randomly to select a word from a cell that is generated by a form field using the "paragraph" answer option.
In one formula:
=index(split(A1," "),randbetween(1,1+len(A1)-len(substitute(A1," ",""))))
Does not remove punctuation.
Anchor the 1s in A1s (ie > A$1s) and can be copied down to suit (for different choices from the same cell).
Let's say you want to get a random word from a string in cell A1:
Get word count:
A2 =if(A1="","",counta(split(A1," ")))
Get random value between 1 and word count:
A3 =randbetween(1,A2)
Get the random word using the random value:
A4 =index(split(A1, " "),A3)
Related
I have a column that contains either letters or numbers. I want to add a column identifying whether each cell contains a letter or a number. The problem is that there are thousands of records in this particular database.
I tried the following syntax:
= Table.AddColumn(Source, "Column2", each if [Column1] is number then "Number" else "Letters")
My problem is that when I enter this, it returns everything as "Letter" because it looks at the column type instead of the actual value in the cell. This remains the case even when I change the column type from Text to General. Either way, it still produces "Letter" as it automatically assigns text as the data type since the column contains both text and numbers.
Use this expression:
= Table.AddColumn(Source, "Column2", each if List.Contains({"0".."9"}, Text.Start([Column1], 1)) then "Numbers" else "Letters")
Note: It would have been smart to add sample data to your question so I wouldn't have to guess what your data actually looks like!
Add column, custom column with
= try if Value.Is(Number.From([Column1]), type number) then "number" else "not" otherwise "not"
Peter's method works if the choice is AAA/111 but this one tests for A11 and 1BC as well
Most formulas I already checked are about finding if a specific cell exists in a range.
I am trying to check the opposite, if values from a specific range exist as substring in a specific cell.
Example, my range A1:A10 is:
Juan Lopez
John Smith
Philip Sue
Philip Stark
Ronaldo Doe
And I want to check of any one of these values in the range exist in my cell C1
C1 = "Senior Designer: Philip Stark (France)"
the answer should be "Philip Stark"
What formula could I use for this?
Until now I have used :
=SUMPRODUCT(--ISNUMBER(SEARCH($A$1:$A$10,C1)))>0
This return true/false if value in range exists in target cell C1. But how can I get the Value from Range?
This will return TRUE if any non-blank string from A1:A10 is in C1:
=REGEXMATCH(C1, JOIN("|", FILTER(A1:A10, A1:A10 <> "")))
This will return a range of TRUE/FALSE for every string in A1:A10 if it is in C1 or not:
=INDEX(REGEXMATCH(C1, A1:A10))
And this one will return only strings in A1:A10 which are in C1:
=FILTER(A1:A10, REGEXMATCH(C1, A1:A10))
Mind the special regex chars which should be escaped if they are in those A1:A10 strings (there are none in your example, so I did not add this escaping).
I have a field set that contains bill numbers and I want to sort them first alphabetically then numerically.
For instance I have a column "Bills" that has the following sequence of bills.
- HB200
- SB60
- HB67
Desired outcome is below
- HB67
- HB200
- SB60
How can I use sorting in SSRS Group Properties to have the field sort from [A-Z] & [1 - 1000....]
This should be doable by adding just 2 separate Sort options in the group properties. To test this, I created a simple dataset using your examples.
CREATE TABLE #temp (Bills VARCHAR(20))
INSERT INTO #temp(Bills)
VALUES ('HB200'),('SB60'),('HB67')
SELECT * FROM #temp
Next, I added a matrix with a single row and a single column for my Bills field with a row group.
In the group properties, my sorting options are set up like this:
So to get this working, my theory was that you needed to isolate the numeric characters from the non-numeric characters and use each in their own sort option. To do this, I used the relatively unknown Regex Replace function in SSRS.
This expression gets only the non-numeric characters and is used in the top sorting option:
=System.Text.RegularExpressions.Regex.Replace(Fields!Bills.Value, "[0-9]", "")
While this expression isolates the numeric characters:
=System.Text.RegularExpressions.Regex.Replace(Fields!Bills.Value, "[^0-9]", "")
With these sorting options, my results match what you expect to happen.
In the sort expression for your tablix/table which is displaying the dataset, set the sort to something like:
=IIF(Fields!Bills.Value = "HB67", 1, IIF(Fields!Bills.Value = "HB200", 2, IIF(Fields!Bills.Value = "SB600", 3, 4)))
Then when you sort A-Z, it'll sort by the number given to it in the sort expression.
This is only a solution if you don't have hundreds of values, as this can become quite tedious to create if there's hundreds of possible conditions.
I have a list of all 5 digit combinations possible and I also have a sentence in which I would like to add each number. Here's an example:
List items:
11111, 22222, 33333.. etc
Sentence:
Hello userXXXXX, how are you?
Desired result:
Hello user11111, how are you?
Hello user22222, how are you?
Hello user33333, how are you?
The list of numbers is huge and the sentence keeps changing. I need a way to do this automatically.
Is such a thing possible?
Place the list in column A. Place this template sentence in cell B1:
Hello user XXXXX, how are you?
In C1 enter:
=LEFT($B$1,FIND("XXXXX",$B$1)-1) & INDEX(A:A,ROWS($1:1)) & MID($B$1,FIND("XXXXX",$B$1)+5,9999)
and copy down:
Maybe (Excel), copied across and down to suit:
=SUBSTITUTE(B$1,"XXXXX",$A2)
Dim str as String
str = "30 40 50 60"
I want to count the number of substrings.
Expected Output: 4
(because there are 4 total values: 30, 40, 50, 60)
How can I accomplish this in VB6?
You could try this:
arrStr = Split(str, " ")
strCnt = UBound(arrStr) + 1
msgBox strCnt
Of course, if you've got Option Explicit set (which you should..) then declare the variables above first..
Your request doesn't make any sense. A string is a sequence of text. The fact that that sequence of text contains numbers separated by spaces is quite irrelevant. Your string looks like this:
30 40 50 60
There are not 4 separate values, there is only one value, shown aboveāa single string.
You could also view the string as containing 11 individual characters, so it could be argued that the "count" of the string would be 11, but this doesn't get you any further towards your goal.
In order to get the result that you expect, you need to split the string into multiple strings at each space, producing 4 separate strings, each containing a 2-digit numeric value.
Of course, the real question is why you're storing this value in a string in the first place. If they're numeric values, you should store them in an array (for example, an array of Integers). Then you can easily obtain the number of elements in the array using the LBound() and UBound() functions.
I agree with everything Cody stated.
If you really wanted to you could loop through the string character by character and count the number of times you find your delimiter. In your example, it is space delimited, so you would simply count the number of spaces and add 1, but as Cody stated, those are not separate values..
Are you trying to parse text here or what? Regardless, I think what you really need to do is store your data into an array. Make your life easier, not more difficult.