SUMIF criteria

12 replies [Last post]
Wes
Offline
Last seen: 6 days 1 hour ago
Title:
Joined: 21 May 2016
Posts: 6
I am trying to sum a column of numbers in column “B” if the last four digits of a date, i.e. “4/2016” found in column “C” is equal to “2016”. Some of the dates in column “C” end in 2014 some 2015 and I do not want them included in my total for column “B”. I am using the SUMIF function and end up with either a 509 error or #Value! error. Any ideas what I might try? Thank you,

Wes

Lupp
Lupp's picture
Offline
Last seen: 1 day 16 hours ago
Title: ★★★★★
Joined: 1 Aug 2012
Posts: 1515
Need info
The “dates” you mention seem to indicate only months. Are they full dates formated to “M/YYYY” or are they actually texts? How did you use SUMIF – what formula did you try? (Use the tool ‘Inline Format as Code’, please.)

Currently installed: LibO V5.1.2 on Windows 10
Maybe we might! (Create a powerful UFO: United Free Office!) Lupp from München
mark_t
Offline
Last seen: 8 hours 17 min ago
Title: ★★★★
Joined: 26 Apr 2016
Posts: 90
Assuming the cells format as date
Assuming the cells format as date try:

=SUMIF ( YEAR ( C11:C14 ) , 2016, B11:B14 )

but note that the functions should be entered using the function wizard and check the Array checkbox at the bottom left of the wizard.

LibreOffice 5.1.3.2, Windows 8.1
Wes
Offline
Last seen: 6 days 1 hour ago
Title:
Joined: 21 May 2016
Posts: 6
Thank you. I have tried this
Thank you. I have tried this from the function wizard and get #Value! error. The cells in column “C” are formatted as Date. Something I find interesting is that I get the same error if I just put the formula Year(C11) in an empty cell and there is a date in cell C11. If cell C11 is empty, I get the number 1899.
mark_t
Offline
Last seen: 8 hours 17 min ago
Title: ★★★★
Joined: 26 Apr 2016
Posts: 90
The data in C11 is probably
The data in C11 is probably not being recognized as a date and is being treated as text. I duplicated this by typing the date as 01-12-2014 which gives #VALUE error, but type 1-dec-2014 in the cell gave displayed text of 01/12/14 and the correct result of 2014.

Use format cells for C11, make sure category is Date, check format string against the displayed value, and if these two formats do not match then LibreOffice has not recognized the data entered as a date.

If you change the date format of the cell to match the format of your data, then LibreOffice will insert an apostrophe at the first character of your data and continue to treat the data as text. After changing the date format you need to remove the apostrophe. I tried using find and replace but this doesn’t seem to work in this case.

If you have a lot of dates to re-format, one thing I found to work was to format a different cell as the date format to match your data, then set that cell = C11. So you could probably create a new column, set it’s date format, use = to set to data from your existing column, then copy and paste that new column to itself as values to remove the formula, and then remove the old column.

Hopefully someone with more experience in LibreOffice has a better solution for correcting the date format of already entered data.

LibreOffice 5.1.3.2, Windows 8.1
Wes
Offline
Last seen: 6 days 1 hour ago
Title:
Joined: 21 May 2016
Posts: 6
Thank you so much! I have
Thank you so much! I have also used RIGHT(CELL,4) and can get it to return “2014” so it would seem that I should be able to use this in combination with SUMIF in some way to get the desired results. Any thoughts on this approach? Thanks again.

Wes

mark_t
Offline
Last seen: 8 hours 17 min ago
Title: ★★★★
Joined: 26 Apr 2016
Posts: 90
Should be ok if you never
Should be ok if you never need to use the data in any other date functions.

=SUM ( IF (RIGHT ( C11:C14 , 4 ) ="2015", B11:B14 ,0 ) )

Need to make sure to test the result against “2015” instead of 2015, and still need to set the Array checkbox in the function wizard.

LibreOffice 5.1.3.2, Windows 8.1
Wes
Offline
Last seen: 6 days 1 hour ago
Title:
Joined: 21 May 2016
Posts: 6
Well, it seems that gives me
Well, it seems that gives me an “#NAME?” error.
Lupp
Lupp's picture
Offline
Last seen: 1 day 16 hours ago
Title: ★★★★★
Joined: 1 Aug 2012
Posts: 1515
Shouldn't you...
…better post a relevant example?

If you set the ‘Numbers’ format of a cell to anything, e.g. “M/YYYY”, this will not mean anything for the content. If the content is of type text the ‘Numbers’ format will not afflict at all the display. Use ‘View’ > ‘Value Highlighting’, and you will get numbers in blue, text in black, and formula results in green. You may also ask any cell, say A1, by =ISTEXT(A1) whether its value (constant or result) is text. …
Without sufficient info we are just stabbing in the dark. Knowing the actual situation this is surely very simple.


Currently installed: LibO V5.1.2 on Windows 10
Maybe we might! (Create a powerful UFO: United Free Office!) Lupp from München
Wes
Offline
Last seen: 6 days 1 hour ago
Title:
Joined: 21 May 2016
Posts: 6
Firstly, I want to thank you
Firstly, I want to thank you very much for taking your time to try and assist me with my problem. You are absolutely correct in saying that this should be very simple and that is isn’t is frustrating to me as well. I will continue my “stabbing in the dark” and will either get it or not. Thanks again.

Wes

mark_t
Offline
Last seen: 8 hours 17 min ago
Title: ★★★★
Joined: 26 Apr 2016
Posts: 90
“#NAME?” suggests one of the
“#NAME?” suggests one of the functions is not spelt correctly.

I’ve also seen some strange characters inserted by copy and paste from forum posts, different quote characters seems quite common.

Also I find I need to add spaces when posting on this forum to avoid 0 ) showing as Innocent etc.

LibreOffice 5.1.3.2, Windows 8.1
Wes
Offline
Last seen: 6 days 1 hour ago
Title:
Joined: 21 May 2016
Posts: 6
Hi Mark, I just want to
Hi Mark,

I just want to thank you again for taking your time to try and help me with my problem. As a result of your suggesting to try some things and comments you have made, I was able to eventually figure out what was going on and why, and more importantly, come up with the formula that worked! Thanks again for your assistance! It was key in getting my spreadsheet to work. Thank you, thank you.

Wes

Lupp
Lupp's picture
Offline
Last seen: 1 day 16 hours ago
Title: ★★★★★
Joined: 1 Aug 2012
Posts: 1515
Just a remark
This is a place for kind and polite people, of course. It’s your place, thus, “Wes”.

It is also a place where LibreOffice users having a problem are looking for a solution. In many cases they accept the suggestion to first look for advice already available from stored threads, instead of readily post a new question.

Such users would surely appreciate to find, at the end of a thread, not only a “Done!”, but also a clarification about what had actually caused the problem, and in what way, exactly, it was solved. An additional [SOLVED] prefixed to the original question by editing, would also be applauded.


Currently installed: LibO V5.1.2 on Windows 10
Maybe we might! (Create a powerful UFO: United Free Office!) Lupp from München

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.