Google Apps Script to highlight a cell when a column contains specific text X number of times - google-apps-script

I’m looking to achieve the following however am unable to with conditional formatting.
I have a sheet whereby staff will input ‘Leave’ on days they are on leave and ‘Office Day’ in days they will be in the office (other days will be WFH and not inputted).
I want to be able to highlight cells when a column has X number of ‘Leave’ cells (so 15 or more would be Light red, 11-14 would be orange and 10 and less would be green for example) and also highlight cells when there are X number of ‘Office Days’ (i.e 8 or more would be dark red, 6-7 would be purple and 5 and less would be blue) so we can manage capacity.
I’m not sure if I can achieve this with a script instead?

You can do this entirely with conditional formatting. Assuming your "Leave" and "Office Day" values are in column B, you can use the following custom formulas as conditional format rules applied to all of column B:
=AND(COUNTIF(B:B, "Leave")>=15, B1="Leave")
=AND(COUNTIF(B:B, "Leave")>=11, COUNTIF(B:B, "Leave")<15, B1="Leave")
=AND(COUNTIF(B:B, "Leave")<=10, B1="Leave")
=AND(COUNTIF(B:B, "Office Day")>=8, B1="Office Day")
=AND(COUNTIF(B:B, "Office Day")>=6, COUNTIF(B:B, "Office Day")<8,B1="Office Day")
=AND(COUNTIF(B:B, "Office Day")<=5, B1="Office Day")

Related

Conditional format of cell with different data types in SSRS?

I am trying to add a fill color to a table that I created in SSRS. The data looks like the table as follows:
The task is whenever the value is over 7, then color the cell green, when the value is less than 7 then orange and if the value is below zero then the due time changes to a sentence as shown with ID 2 and is to be colored red.
I have achieved coloring the cells when greater than or less than 7 using the if statement on the Due(Mins) field value however, it fails to color the cell red when less than 0. I have used switch, instr functions, but haven't had any luck.
Can emphasize more. Appreciate the help.
Cheers,
Sid
=SWITCH(
Fields!Due.Value.ToString.Contains("OverDue"), "Red",
VAL(Fields!Due.Value) > 7, "Green",
True, "Orange"
)
Switch will stop when it hits the first expression that evaluates to True
So...
First we test if the value contains overdue and set red
Then we test if the value is greater than 7 and set the result to Green
The True at the end acts like an else

How to show % of the total to each bar in bar graph Tableau

I have an existing bar chart for a given metric that I'm trying to add a % label to each bar (customer x) to show the % of the total of another bar (All-Customers). I do not want it to replace the "Data Volume" label at the top of the each bar. I would prefer to show each customer's percentage of data volume compared to All-Customers in the Tooltip.
In my sample file, customer is simply a number (1 thru 7). Customer 99 represents All-Customers and is the sum of each customers Data Volume. In my Tableau sheet, I made a calculated field called "Graph Labels" which takes makes my customer labels for each bar. It adds the letter "C" to the customer #.
IF [Customer] = "99" THEN "All-customers"
ELSE "C"+STR([Customer])
END
Note: I must be able to use Graph Labels as it is in my case. See the link for the photo of my worksheet showing the bar chart.
Data Volume Bar Chart Tableau
Here's a screenshot of what I did...
A few points:
Instead of using "All Customers" as your last row, I filtered that one out (customer "99") and used the Row Grand Totals from the menu "Analysis > Totals > Show Row Grand Totals".
I kept the labels as they are, but I also added the SUM(Data Volumes) in the tooltip. Only difference is that I applied a quick table calculation by right clicking on that field and selecting "Quick Table Calculation > Percent of Total".

Creating a Report in SSRS

I am attempting to create a report to change Values to Red, Yellow and Green based upon the last inspection date. Inspections are every three years if DUE is in the last inspection then I want the cell to turn red, if the last inspection has been in the last 2 years I need it green and in the year that it needs and inspection I need it yellow.
Here is what I have NOT working :)
=SWITCH(Fields!Inspection_x0020_Expires0.Value = "DUE","Red"),
(Fields!Last_Inspection.Value = "d" < 730,"Yellow")
(Fields!Last_Inspection.Value = "d" > 730,"Green")
Thank you for taking the time to help me.
Tim
Use the DATEDIFF function to compare the last inspection date to today.
DateDiff(DateInterval.Day, Fields!Last_Inspection.Value, Today) < 730
Here is what I ended up doing, I added a column Named Textbox6 and calculated the number of days with a DateDiff =DateDiff("d", Fields!Inspection_x0020_Expires0.Value, Today()) to get the number of days and then I used that value to create my background text box color
=Switch (Not(isNothing(Fields!Last_Inspection.Value)) and ReportItems!Textbox6.Value <= 729, "Green", ReportItems!Textbox6.Value >= 730 and ReportItems!Textbox6.Value <=1094 , "Yellow", isNothing(Fields!Last_Inspection.Value) or ReportItems!Textbox6.Value>1094, "Red" )

Color chart bars depending on category group value

I have the following chart (ssrs 2008), it shows sales according to #FromDate and #ToDate parameters.
The data is correct.
The problem is that when it shows comparison between years (=more than one year for the same month on a chart), the color stays the same, as you can see in months 4, 5, 6, 7:
How can i change it?
I would appreciate your help
There are a few different web descriptions with overviews of controlling the bar colors in a chart, such as this at learn.microsoft.com or Change the series colors for a bar chart (Images are currently dead in this, limiting its helpfulness).
The key is finding the "Series Properties" dialog and the "Fill" section, where you can specify the fill color: Use an expression such as:
=IIF(YEAR(Fields!MyDateField.Value) mod 2 = 0, "#FF0000", "#00FF00")
To Add some more explanation to JamieFs answer. This is the steps that I followed:
Right click on the series Select "Series Properites..."
Go to Fill:
Press the Expression button(Fx) and type in your equation to calculate the colour:

How do i execute a function when text changes in a cell? (google docs)

I've been lookin for a function to change the color of all cells in a row, when some text in a certain cell equals something. I found it here:
Google Spreadsheet: Script to Change Row Color when a cell changes text;
My question is, how can i execute this function, when the text changes?
Search for the function onEdit.
https://developers.google.com/apps-script/guide_events
Given when some text in a certain cell equals something Conditional Formatting may be much simpler. onEdit would be required if the change is from 'any value' to 'any other value' (so potentially from y to x as well from x to y) but CF can be triggered in cases such as:
"from less than 100 to 100 (or to 100 or more than 100), etc.",
"from Pending to Complete (or to any member of a list such as Abandoned, Transferred, Rescheduled, etc.)",
"from more than a year left to less than a month (or a week, or 4 days, etc.)",
"from any one of Red, Orange, Yellow to Green or Blue (or either Indigo or Violet, etc.),
"from being a unique entry in a list to being a duplicate (ie without changing its own value becomes equal to any other entry)