[Solved] Mixing concatenate and if statements?
-
- Posts: 16
- Joined: Thu Jun 23, 2016 4:42 pm
[Solved] Mixing concatenate and if statements?
I've got data that needs to be massaged prior to exporting to a CSV file for importing. I have a spreadsheet with multiple columns with data and multiple sheets. Such as one sheet has T2 is AUTHOR1, U2 is AUTHOR2, V2 is AUTHOR3 and W2 is AUTHOR4. Not all rows have data in them, but I need to combine these columns that have data into a new column of text, with each column of text separated by a " - ". It's easy to combine these if each column has text...the problem is when a column is missing data.
My formula is: ="AUTHORS: "&TRIM($'Auction Items'.T2)&" ["&TRIM($'Auction Items'.X2)&"]" & " - "&TRIM($'Auction Items'.U2)&" - "&TRIM($'Auction Items'.V2)&" - "&TRIM($'Auction Items'.W2)&" ARTIST: "&TRIM($'Auction Items'.Y2)
Result: AUTHORS: Robert E. Pinkerton [Wi-Di-Go] - S. Omar Barker - Hugh Pendexter - Arthur D. Howden Smith ARTIST: Walter Baumhofer
The problem combination with blank cells results with:
AUTHORS: Steuart M. Emery [The Poison Patrol] - Perry Paul - - ARTIST: Chris Schaare
Those darn extra "-".
I was wondering if I could eliminate those extra spaces and "-" using a IF, in that if the cell doesn't contain text then don't bother adding " - ". But no matter how I try to use this, I come up with an error message.
Please help!
My formula is: ="AUTHORS: "&TRIM($'Auction Items'.T2)&" ["&TRIM($'Auction Items'.X2)&"]" & " - "&TRIM($'Auction Items'.U2)&" - "&TRIM($'Auction Items'.V2)&" - "&TRIM($'Auction Items'.W2)&" ARTIST: "&TRIM($'Auction Items'.Y2)
Result: AUTHORS: Robert E. Pinkerton [Wi-Di-Go] - S. Omar Barker - Hugh Pendexter - Arthur D. Howden Smith ARTIST: Walter Baumhofer
The problem combination with blank cells results with:
AUTHORS: Steuart M. Emery [The Poison Patrol] - Perry Paul - - ARTIST: Chris Schaare
Those darn extra "-".
I was wondering if I could eliminate those extra spaces and "-" using a IF, in that if the cell doesn't contain text then don't bother adding " - ". But no matter how I try to use this, I come up with an error message.
Please help!
Last edited by Hagar Delest on Wed Nov 07, 2018 10:43 pm, edited 1 time in total.
Reason: tagged solved
Reason: tagged solved
OpenOffice 4.1.2 on Mac Os X
Re: Mixing concatenate and if statements?
A sample of what you have tried, and the related error messages, would help.
A simple example that uses the dash if the cell A1 is empty, else the cell value:
Adapt this to your needs.
A simple example that uses the dash if the cell A1 is empty, else the cell value:
Code: Select all
=IF(ISBLANK(A1);"-";A1)
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Re: Mixing concatenate and if statements?
What about
As robleyd states, an idea as to what you have tried and the relevant error messages would help, but I think what I have given will handle what you are asking for.
If it doesn't work, please include the results that you actually got and what you actually expected. If there's an error message, be sure to include all of the information from that message.
Code: Select all
=trim(substitute("AUTHORS: "&$'Auction Items'.T2)&" ["&$'Auction Items'.X2&"]" & " - "&$'Auction Items'.U2&" - "&$'Auction Items'.V2&" - "&$'Auction Items'.W2&" ARTIST: "&$'Auction Items'.Y2;"- -";""))
If it doesn't work, please include the results that you actually got and what you actually expected. If there's an error message, be sure to include all of the information from that message.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
-
- Posts: 16
- Joined: Thu Jun 23, 2016 4:42 pm
Re: Mixing concatenate and if statements?
Thanks gents. My error was using a wrong statement. I've written a ton of dBase code, and have been dabbling with OpenOffice more recently, so I wrote something like: if(T2#" "; T2) Or something just as inelegant. What I really need is to include those cells that are not blank, and then add the " - " if the next cell is NOT blank. If push comes to shove, I could always remove those extra " - " from the CSV once it's saved, but there could be anywhere from 1 to 3 extra " - ", and it's not as tidy.
OpenOffice 4.1.2 on Mac Os X
Re: Mixing concatenate and if statements?
My usage of the substitute function should eliminate the extraneous -'s
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
-
- Posts: 16
- Joined: Thu Jun 23, 2016 4:42 pm
Re: Mixing concatenate and if statements?
Thanks...but no. Here is the code as recommended within a cell that has several blank cells:
=TRIM(SUBSTITUTE("AUTHORS: " & 'Auction Items'.T5 & " [" & 'Auction Items'.X5 & "]" & " - " & 'Auction Items'.U5 & " - " & 'Auction Items'.V5 & " - " & 'Auction Items'.W5 & " ARTIST: " & 'Auction Items'.Y5 ;"- -";""))
Here are the results:
AUTHORS: Steuart M. Emery [The Poison Patrol] - Perry Paul - - ARTIST: Chris Schaare
In those cases in which there are more than two blank cells returned the following:
AUTHORS: Kenneth Robeson [Lester Dent] [The Lost Oasis] - - - ARTIST: Walter Baumhofer
=TRIM(SUBSTITUTE("AUTHORS: " & 'Auction Items'.T5 & " [" & 'Auction Items'.X5 & "]" & " - " & 'Auction Items'.U5 & " - " & 'Auction Items'.V5 & " - " & 'Auction Items'.W5 & " ARTIST: " & 'Auction Items'.Y5 ;"- -";""))
Here are the results:
AUTHORS: Steuart M. Emery [The Poison Patrol] - Perry Paul - - ARTIST: Chris Schaare
In those cases in which there are more than two blank cells returned the following:
AUTHORS: Kenneth Robeson [Lester Dent] [The Lost Oasis] - - - ARTIST: Walter Baumhofer
OpenOffice 4.1.2 on Mac Os X
Re: Mixing concatenate and if statements?
Please attach a sample of your spreadsheet, as we're just giving you best guesses without having a sample to see how your data is actually laid out.
See [Forum]How to attach a document for information regarding attaching a document
See [Forum]How to attach a document for information regarding attaching a document
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
-
- Posts: 16
- Joined: Thu Jun 23, 2016 4:42 pm
Re: Mixing concatenate and if statements?
I've attached a small sample of the spreadsheet. Thanks for your help.
John Gunnison
John Gunnison
- Attachments
-
- catalog_SAMPLE.xls
- (33.5 KiB) Downloaded 77 times
OpenOffice 4.1.2 on Mac Os X
Re: Mixing concatenate and if statements?
I suggested the use of IF() and ISBLANK() earlier in the topic, so I'll put my solution forward based on those functions. Sheet3 of the attached document has one column which concatenates the author(s)/artist information. It appears to handle the situation of gaps in the author columns - e.g. author2 is blank but author3 has content. Note that author1 must have content as it stands - although it would be easy enough to add a test for blank on that column as well.
You could handle the absence of an artist name similarly allowing you to leave out the word ARTIST if such were needed.
You could handle the absence of an artist name similarly allowing you to leave out the word ARTIST if such were needed.
- Attachments
-
- catalog.ods
- (16.52 KiB) Downloaded 88 times
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
-
- Posts: 16
- Joined: Thu Jun 23, 2016 4:42 pm
Re: Mixing concatenate and if statements?
An elegant solution. Although one side question... does the use of "&" not work, where concatenate does?
OpenOffice 4.1.2 on Mac Os X
Re: [Solved] Mixing concatenate and if statements?
I'd recommend using one or the other, just depending on how you want your statement configured.
If the formulas work with CONCATENATE, then they would work (with some modifications) with the &
The modifications would be to allow the usage of the & where the CONCATENATE function uses a ;
There might (I haven't looked at robleyd's spreadsheet) be situations where the usage of the & makes it more difficult to write.
If the formulas work with CONCATENATE, then they would work (with some modifications) with the &
The modifications would be to allow the usage of the & where the CONCATENATE function uses a ;
There might (I haven't looked at robleyd's spreadsheet) be situations where the usage of the & makes it more difficult to write.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
Re: [Solved] Mixing concatenate and if statements?
I chose to use CONCATENATE for the overall joining of text elements, and the shortcut & within the IF statements, to hopefully make the end formula a little easier to read, and distinguish between the outer and inner concatenations.
A tip; when I am developing 'complex' formulae, I use a text editor to allow me to 'pretty print' the formula so I can see the individual elements of the formula. I then copy the formula into Calc. For example, this is how the formula in my uploaded file looks when neatly formatted - each line is one argument to CONCATENATE:
Of course, CONCATENATE is limited to 30 arguments, where you can use & for larger numbers of strings.
A tip; when I am developing 'complex' formulae, I use a text editor to allow me to 'pretty print' the formula so I can see the individual elements of the formula. I then copy the formula into Calc. For example, this is how the formula in my uploaded file looks when neatly formatted - each line is one argument to CONCATENATE:
Code: Select all
=CONCATENATE(
"AUTHORS: ";
$'Auction Items'.T2;
" [";
$'Auction Items'.X2;
"]";
IF(ISBLANK($'Auction Items'.U2);"";" - " & $'Auction Items'.U2) ;
IF(ISBLANK($'Auction Items'.V2);"";" - " & $'Auction Items'.V2) ;
IF(ISBLANK($'Auction Items'.W2);"";" - " & $'Auction Items'.W2) ;
" ARTIST: ";
$'Auction Items'.Y2
)
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
-
- Posts: 16
- Joined: Thu Jun 23, 2016 4:42 pm
Re: [Solved] Mixing concatenate and if statements?
Never thought of that. Looks like dBase coding at that point.
John G.
John G.
OpenOffice 4.1.2 on Mac Os X
Re: [Solved] Mixing concatenate and if statements?
Oy! No need to be rude about itLooks like dBase coding at that point.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Re: [Solved] Mixing concatenate and if statements?
There are not many of us left who remember dBase!
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: [Solved] Mixing concatenate and if statements?
And of those few, I suspect some would prefer to forget...
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers