Ask Your Question
1

Calc - conditional formatting based on month value from date

asked 2017-02-28 03:25:23 +0200

Pheeble gravatar image

One of the columns in my Calc spreadsheet is the date of each transaction, with the number type set to 'date'. I want these date cells to be grouped by having a background colour based on the month value - so all cells containing dates in January have one colour, those containing dates in February another colour, etc.

I thought I could use conditional formatting with the 'Color Scale (2 Entries)' option and a formula to get this to work but after wasting about an hour on this I haven't been able to get it to work. I'm not sure I understand how this is supposed to work. I've gone through the help documentation but that didn't provide any clues.

Using the 'Conditional Formatting' dialog for the range A3:A1048576 I've selected 'All Cells' and 'Color Scale (2 Entries)'. What formula do I put into the 'Formula' boxes for each colour to achieve this? I've tried '=(MONTH(A3)=1' and '=(MONTH(A3)=12' as the min and max values but there is never any change to the background colour.

What is the correct way to use a formula for specifying a colour scale in the conditional formatting dialog?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2017-02-28 07:53:53 +0200

Please see here for an explanation of the feature.

In essence, this is what you actually do. Let's say you have Feb 28 in A3. Then your formatting is translated to this: "If a cell in range has value less that or equal to formula MONTH(Feb 28)=1 (i.e. FALSE, or 0) then apply color 1; else if its value is greater than or equal to formula MONTH(Feb 28)=12 (i.e. FALSE again, or 0) then apply color 2; else create gradient". As you see, this is an invalid condition, where both limits are the same, so nothing happens. Again: the "All cells" condition is always applied to cell values as whole; formula is used only to calculate the reference value.

I suggest you to use Formula is instead of All cells, and create 12 conditions. That is not that much, and also would allow to use custom color values instead of automatically computed.

edit flag offensive delete link more

Comments

Ok, thanks for that. It's sometimes difficult to find helpful information about LibreOffice, documentation being the poor relation of development. Also, I didn't realize I would have to create a separate condition for each month. The 'formula' processing seems to be much less capable than I was expecting.

Pheeble gravatar imagePheeble ( 2017-03-01 01:35:31 +0200 )edit
1

answered 2017-02-28 11:14:19 +0200

JohnSUN gravatar image

In addition to the recommendations Mike Kaganski, I want to recall an old trick, which, to my knowledge, is not available in some other office suites - using function STYLE() in conditional formatting. Of course, this does not release you from the creation of 13 different styles (one style used to leave an empty cells without color). But the condition in the conditional formatting is only one. See this file - C:\fakepath\12ColorsFor12Month.ods

edit flag offensive delete link more

Comments

Wow great! I never understood the purpose of that function before.

Mike Kaganski gravatar imageMike Kaganski ( 2017-02-28 11:20:11 +0200 )edit

Please note that the "trick " comes with disadvantages.
1) It does not overlay a format conditionally for the view as CF does.
2) It actually assigns the named cell style to the respective cells.
3) As the calculation is part of a CF condition this is only done for cells if once the cell gets part of the view.
4) (Beware!) If a user routine should ask for the cell style the result will depend on the history with respect to this.
5) There are style aware features, alas!

Lupp gravatar imageLupp ( 2017-02-28 14:48:10 +0200 )edit

See also this thread in the other forum, in specific my first comment there mainly directed @keme.
Do you want a demo?

Lupp gravatar imageLupp ( 2017-02-28 15:20:51 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-02-28 03:25:23 +0200

Seen: 817 times

Last updated: Feb 28 '17