Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Evan0211
Creator
Creator

Getting a SubField to the left of the last '-' in a string

I am working on a SubString function to get the data to the LEFT of the final dash (-) in the string.  

For example:

vString = 'Test - Test Bed 1 - New Form - 1110012'

The expected result would be: Test - Test Bed 1 - New Form

I have used 

SubField('Test - Test Bed 1 - New Form - 1110012','-',1)

and it works for the first instance of the - (returning Test) but I need to essentially do it in reverse to get everything from the left of the final -

Labels (1)
1 Solution

Accepted Solutions
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Here is the expression.

Left('Test - Test Bed 1 - New Form - 1110012',index('Test - Test Bed 1 - New Form - 1110012','-', SubStringCount('Test - Test Bed 1 - New Form - 1110012','-'))-1)

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!

View solution in original post

5 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Try this.

SubField('Test - Test Bed 1 - New Form - 1110012','-',SubStringCount('Test - Test Bed 1 - New Form - 1110012','-')+1)

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Evan0211
Creator
Creator
Author

That gives me what is to the right of the final (-) which is 1110012.  I need what is to the left of it. 

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Ohh My bad, sorry I misunderstood it. I will send you the new expression.

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Here is the expression.

Left('Test - Test Bed 1 - New Form - 1110012',index('Test - Test Bed 1 - New Form - 1110012','-', SubStringCount('Test - Test Bed 1 - New Form - 1110012','-'))-1)

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
MarcoWedel

another possible solution might be:

Left('Test - Test Bed 1 - New Form - 1110012',Index('Test - Test Bed 1 - New Form - 1110012','-',-1)-1)