Having issues with a substring function in Tableau - tableau-api

I am trying to break a string up into substrings based on the position of a repeating set of characters.
The source string [UPDATES] looks like this, the number of characters between the repeating portions varies wildly.
"04/24/15 15:12:54 (PZPJ3F): Task update. 04/24/15 15:12:54 (PZPJ3F): Task update. 04/22/15 15:17:13 (SZGQ3T): updated due date prior to global problem 04/22/15 12:28:09 (PZPJ3F): Task updates."
I am trying to break them up into separate substrings so that I can display them side by side as separate columns as below
Column1 = |04/24/15 15:12:54 (PZPJ3F): Task update.
Column2 = |04/24/15 15:12:54 (PZPJ3F): Task update.
Column3 = |04/22/15 15:17:13 (SZGQ3T): updated due date prior to global problem|
I got the first portion to work with
LEFT([UPDATES],FIND([UPDATES],"): ",28)-27)
But my attempts at using FIND to locate the next occurrence of "): " and use it to begin a MID are not working, specifically where I try to end them using a FIND function.
IF [Mark1]>0 THEN MID([UPDATES],[Mark1]-25,[Mark2])
ELSE ""
END
Where Mark1 is
FLOAT(FIND([UPDATES],"): ",(FIND([UPDATES],"): ")+1)))
and Mark2 is
FLOAT(FIND([UPDATES],") ",[Mark1]+1))
I really went down the rabbit hole at the end of my attempt.
I am using Tableau 8.2, so Tableau 9 functions aren't an option (looking forward to FIND Nth!
Thanks in advance.

The key is that find() takes a second optional argument as a start position.
So in Tableau 8.2, I would write a simple calc to find the position of the first separator. Then reference that calculated field twice in your final calculated fields to yield the length of the first substring and the starting point of the second one.
Separating out substrings is painful prior to Tableau 9. Extracting the first in a list isn't bad, getting the second is clumsy and after that it gets pretty ugly.
Best approach is to upgrade to version 9 or do some preprocessing to pull out the substrings.

Related

Why is Arrayformula returning only the first row

Update: sample sheet provided here: https://docs.google.com/spreadsheets/d/1BapXdaVOUL634SstNJXqYNocsD_EvvtlbJ77vlElmZs/edit?usp=drivesdk. Any help will be appreciated!
Hi fellow nerds.
I'm trying to make the current column (most recent interaction date with client) display the max values (most recent dates) from ContactLog!b:b (dates of all recorded interactions), when the client name in ContactLog!A:A matches to the client name in current row column A.
After many days of trying, I've found several formulas to successfully achieve this result for the current cell only.
=MAXIFS(ContactLog!B:B, ContactLog!A:A, A:A)
=MAX(FILTER(ContactLog!B4:B, ContactLog!A4:A=VLOOKUP(A2, ContactLog!A4:B, 1, FALSE)))
=MAX(QUERY(ContactLog!A4:B, ""SELECT B WHERE A = '""&VLOOKUP(A2, ContactLog!A4:B, 1, FALSE)&""'"", 0))
=IF(COUNTIF(ContactLog!A:A, A2),MAX(FILTER(ContactLog!B:B, ContactLog!A:A = A2)),"")
But none of these seem to work with arrayformula, to spread to the entire column. I'd like this result to apply automatically to the entire column (wherever column A is not blank).
It's displaying the correct max value for the first cell (in which the formula is written), and I could drag the formula down, but not spreading automatically as an array.
I've tried using =match with =filter, but that keeps running into mismatched range row sizes. (I've previously solved that by using filter within a filter, but can't figure that out here).
[I have a similar issue for the nearby columns also, "most recent interaction method", and "reminders & goals". The formula there is:
=INDEX(ContactLog!C:C, MATCH(MAX(IF(ContactLog!A:A=A2, IF(ContactLog!B:B=MAX(IF(ContactLog!A:A=A2, ContactLog!B:B)), ROW(ContactLog!B:B)))), ROW(ContactLog!B:B), 0))
And
=IFERROR(CONCATENATE(JOIN(" • ",FILTER(ContactLog!D:D,ContactLog!A:A=A2, ContactLog!D:D<>"")),IF(INDEX(ContactLog!D:D,MAX(IF(ContactLog!A:A=A2,ROW(ContactLog!D:D))))="","","")),"")
They both work great, but I can't get them to work with arrayformula...]
What am I missing?
You can do something like this with BYROW, that allows you to expand your formula through the column and be calculated "row by row". Using your first option:
=BYROW(A:A, LAMBDA (each,IF(each="","",MAXIFS(ContactLog!B:B, ContactLog!A:A, each))))

Smartsheet function is UNPARSEABLE

On the Sheet Summary I'm trying to write a function that will track Past Due tasks below is the format :
=COUNTIF([Is Past Due?]:[Is Past Due?], "Yes")
The formula doesn't work as it says "UNPARSEABLE". Below is the Past Due column name
The UNPARSEABLE error in Smartsheet happens when, the formula has a problem which prevents it from being parsed and interpreted.
Example:
-misspelling
-incomplete operators
-using the wrong case for a column name
-using single quotes instead of double quotes
Maybe, you have to review the syntax of the function COUNTIF, and make sure to use acceptable operators, follow this link for more information about the function
---Syntax---
COUNTIF( range,criterion )
range
— The group of cells to count.
criterion
— The value that determines which cells in the range will be counted.
I hope this information can be useful for you.

Using the toInteger function with locale and format parameters

I've got a dataflow with a csv file as source. The column NewPositive is a string and it contains numbers formatted in European style with a dot as thousand seperator e.g 1.019 meaning 1019
If I use the function toInteger to convert my NewPositive column to an int via toInteger(NewPositive,'#.###','de'), I only get the thousand cipher e.g 1 for 1.019 and not the rest. Why? For testing I tried creating a constant column: toInteger('1.019','#.###','de') and it gives 1019 as expected. So why does the function not work for my column? The column is trimmed and if I compare the first value with equality function: equals('1.019',NewPositive) returns true.
Please note: I know it's very easy to create a workaround by toInteger(replace(NewPositive,'.','')), but I want to learn how to use the toInteger function with the locale and format parameters.
Here is sample data:
Dato;NewPositive
2021-08-20;1.234
2021-08-21;1.789
I was able to repro this and probably looks to be a bug to me . I have reported this to the ADF team , will let you know once I hear back from them . You already have a work around please go ahead that to unblock yourself .

TSQL Find and Replace in String

I have a table that I use for error logging when inserts fail on the front end of my site. It stores the params URL as a text string so we can see what values were sent over and why it may have failed.
Well I am now working with this data to try and recover some records from it.
This is what the record looks like in my field:
xml=<data><optional><Account>192070041</Account></optional></data>, submitter=Q1370, target=Q1234, escalationType=esc, escalationReason=277, feedback=cx req live esc to have us release his alh payment for 8487.18, adv cx his funds are eligble for release on july 2nd at 445 pm est, preventable=0,
The issue I am running into recovering some data is that on a script I am writing in PHP, I am getting all of the params individualy by exploding on the = sign to get each of the values.
Well, the feedback= section happens to be comments that contains commas and its messing up a lot of stuff.
What I need to do is within the string, I need to find everything in feedback=xxxxxxxxxx, and either remove all the commas from that section or replace with with a | pipe so I can just change them back later.
My lack of knowledge in this area is where I hope some one can point me in the right direction so I can get some records restored on a mass level.
Example:
Before String - param1=dfsfsf, param2=fdsfsdfds, param3=bob, how are you doing today?
After String - param1=dfsfsf, param2=fdsfsdfds, param3=bob| how are you doing today?
UPDATE YourTable SET URL=REPLACE(URL,',','|')
See https://msdn.microsoft.com/en-us/library/ms186862.aspx and https://msdn.microsoft.com/en-us/library/ms181984.aspx
Later edit: I read your question more carefully and I now understand that you want to replace only the commas in after a certain substring. Try something like this:
DECLARE #URL NVARCHAR(1000)
SET #URL='Before String - param1=dfsfsf, param2=fdsfsdfds, param3=bob, how are you doing today?'
SELECT LEFT(#URL,ISNULL(NULLIF(CHARINDEX('param3=',#URL),0),LEN(#URL)))
+ISNULL(REPLACE(SUBSTRING(#URL,NULLIF(CHARINDEX('param3=',#URL),0),1000),',','|'),'')

Multiple Search in SSRS when using only a part of the field

I Have created a stored procedure:
#DeviceID nvarchar(20) =''
WITH EXECUTE AS CALLER
AS
SELECT
amd.BRANDID,
amd.DEVICEID
FROM AMDEVICETABLE amd
where
left(amd.Deviceid,len(#DeviceID)) in (#DeviceID)
The length of amd.Deviceid is about 15 characters
In Visual Studio I create a parameter #DeviceID and when I am entering e.g ABCDE ( the first 5 characters from Deviceid) everything is working perfect.
the problem is that I want to put multiple values like
jhmcl*, jhmgd*.
So I created my own little version of your report and I believe the problem is your LEN() function. I'm surprised it doesn't return an error because it errors out in Report Builder for SQL Server 2014(simple version of SSRS). I would test what your LEN(#DeviceID) is returning. I would bet it's not returning the correct value. Instead you might try this to cover every possible pattern. I don't know how it will work performance wise.
SELECT DeviceID
FROM YourTable
WHERE LEN(DeviceID,1) IN (#DeviceID)
OR LEN(DeviceID,2) IN (#DeviceID)
OR LEN(DeviceID,3) IN (#DeviceID)
..
OR LEN(DeviceID,15),IN(#DeviceID)