Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
rustyfishbones
Master II
Master II

Remove first and last comma

Hi All,

I have a field with comma separated values, like below

, PB , D , 28006 , 0 , 0 ,   9 ,

I am using SUBFIELD(MyField,',',) as MyNewField

however I keep getting blank values for the first and last comma

I want to remove the first and last comma while still using the above SUBFIELD Function

Regards

Alan

1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

If you know that the string always starts and ends with commas, you can use

     Subfield( Mid( MyField, 2, Len(MyField)-2 ), ',' )

HIC

View solution in original post

16 Replies
rustyfishbones
Master II
Master II
Author

REPLACE will remove the first, but not the last comma it seems

nizamsha
Specialist II
Specialist II

can u send sample excel

hic
Former Employee
Former Employee

If you know that the string always starts and ends with commas, you can use

     Subfield( Mid( MyField, 2, Len(MyField)-2 ), ',' )

HIC

rustyfishbones
Master II
Master II
Author

Hi,

please see the attached excel file example

Regards

Alan

Not applicable

Hi

what about cutting the first and last two chars similar to this:

=SUBFIELD(MID(InPut, 2, Len(Input)-2) , ',')

Hth

Roland

rbecher
MVP
MVP

Hi Alan,

what is the source of the field? Maybe you can just read it like a CSV source?

- Ralf

Astrato.io Head of R&D
rustyfishbones
Master II
Master II
Author

Thanks HIC, t

his is correct for what I asked

However I just noticed that all have a Comma at the End of the String but not all start with a Comma

hic
Former Employee
Former Employee

Then try

     Subfield(

          IF( Left(Trim(MyField),1)=',', Mid( Trim(MyField), 2, Len(Trim(MyField))-2 ), ',' ),

               Left( Trim(MyField), Len(Trim(MyField))-1 ),

           ',' ) )


HIC

rustyfishbones
Master II
Master II
Author

Hi Ralf,

I am actually taking it from a Database!!

I believe it's structured that way because of the volume, it's an audit database of all activity in another system

Regards

Alan