Displaying a timeline in crystal reports or excel - sql-server-2005

I have an application that keeps rent periods of a parking lot. I have a SQL database with this information:
idLot dateFrom dateTo
------------------------------------------
1 01/03/2011 30/07/2011
2 01/01/2011 30/05/2011
3 01/02/2011 30/07/2011
6 01/02/2011 30/06/2011
And I need to display the information like the image below.
1
I cannot achive the goal with Excel or Crystal Reports. I also use ComponentOne FlexGrid. Any ideas?
Thanks in advance.

It's not the prettiest option, but you can do this in Excel using the Sumproduct() function. In the screenshot below, the sumproduct goes through each line of your datatable and does 3 things (the selected cell is B17 by the way):
It determines whether each row has the idlot it is looking for (evaluates to true/false)
It determines whether DataFrom is <= the column of your display table (evaluates to true/false)
It determines whether DataTo is >= the column of your display table (evaluates to true/false).
This results in a 0 or 1 in each cell of your display table. This is close, but not exactly what you're looking for. I then added some conditional formatting:
If the result of the equation was 0, then the cell's font is white.
If the result of the equation was 1, then cell's font and background are both green.
When you apply the conditional formatting to the entire graph, you get the last 2 rows, which is green for occupied and white for unoccupied.
The only remaining problem is how to account for a changing number of rows in your table. This can be solved by just setting the ranges in your equation to a very high number.

Related

Excel 2016: Conditional Formatting: Highlight row if cell value is in list

Excel 2016 Conditional Formatting question:
I have two tabs, Data and List:
Data has 5 columns. Column A is the item ID number, the others have
project related data.
List has 1 column. This is a list of ID numbers
that have been processed.
Here is the question:
How do I highlight the rows for processed ID numbers? I want to be able to add ID numbers to List as I process more rows. I want to see processed items in Data in green highlight, because green makes the boss happy!
Looking forward to your input!
I would use a VLOOKUP to find the value in the List sheet. An error means the value doesn't exist. Since you want to know if it does exist, just invert the boolean result with NOT
=NOT(ISERROR(VLOOKUP($A1,List!$A:$A,1,FALSE)))
Note: This is a Classic > Formula formatting rule, and the lookup value is $A1 because my "applies to" range starts on row 1 (and we always look at col A).
Rule:
Formatting Range:
Result:

Dynamic reference in excel formula

I have the following array formula which works for what I want to do but I'm trying to change the formula when a user selects a value.
=INDEX($A$2:$B$70,SMALL(IF($A$2:$B$70=$A$121,ROW($A$2:$B$70)),ROW(1:1))-1,1)
It's used for a monthly report and the user will choose from a drop down the day of the month, e.g 1,2,3 - 31.
So if the user selects 1 from the drop down menu I want the formula to use the above formula.
If they select 2 for example I want the formula to move over a column so it would change to
=INDEX($A$2:$C$70,SMALL(IF($A$2:$C$70=$A$121,ROW($A$2:$C$70)),ROW(1:1))-1,1)
and so on moving over a column at a time.
It this possible at all or can it even be done without VBA?
I have an example of what I want done on the following link
https://docs.google.com/spreadsheets/d/1MDOzoQxYLgW-UOyljZsMwSu8zyAB7O2k1V-bTNP5_F0/edit?usp=sharing
All the data is on the first tab called staff. Each employee has a row and the duty assigned under the corresponding day column.
On the Roster tab it summarises each day. So what I am trying to get to happen is when you choose the day of the month (or preferably the actual date) the sheet changes to reflect the data.
At the moment the code I have working does for just Day 1 because the column references are coded into the formula. I was hoping to somehow choose 6 for example from the drop down and then the formula will map chosen day to the corresponding range in the raw data and update the formula and change the formula from Staff!$A$2:$B$68 to Staff!$A$2:$G$68.
If the formula finds no more entries if shows #NUM! but I intended to use the function ISERROR() to replace #NUM! with "".
This is what I'm trying to achieve it if makes sense?
There are a few issues here/ You are returning the value from column A so the first range can be $A$2:$A$70 and that means you don't need the 1 to specify the column_num. The IF statement was covering A2:C70 when you really only want either B2:70 or C2:C70 depending on the 1 or 2.
Assuming that A122 has either a 1 or 2 in it then,
=INDEX($A$2:$A$70, SMALL(IF(INDEX($B$2:$C$70, 0, $A$122) = $A$121, ROW($1:$69)), ROW(1:1)))
Standard non-array alternative,
=INDEX($A$2:$A$70, SMALL(INDEX(ROW($1:$69)+(INDEX($B$2:$C$70, 0, $A$122) <> $A$121)*1E+99,, ), ROW(1:1)))

How to fill cells based on complicated formula?

I have a complicated formula. What I'm looking to do is to set it up where if column A is YR then column B-J will highlight red if the date is more than 2 years ago and yellow if the date is within 30 days of reaching the 2 year mark.
If column A is P1, P2, P3, P4, or P5 then column B-J will highlight red if the date is more than 1 year ago and yellow if its within 30 days of reaching the one year mark.
You will want to create two conditional formatting rules. First select B2:J6 (as laid out in the image below, the bottom row will vary with your own data) with B2 as the Active Cell. Create a new formula using the Use a formula to determine which cells to format and supply the following for Format values where this formula is true:
=AND(OR($A2="P1",$A2="P2",$A2="P3",$A2="P4",$A2="P5",$A2="YR"),B2<=EDATE(TODAY(),(1+($A2="YR"))*-12))
Click Format and supply a red Fill. I also added a white Font for readability. Click OK to accept the format and then OK again to create the new rule.
With B2:J6 still selected, repeat with the following formula for a yellow fill.
=AND(OR($A2="P1",$A2="P2",$A2="P3",$A2="P4",$A2="P5",$A2="YR"),B2>EDATE(TODAY(),(1+($A2="YR"))*-12),B2<=(EDATE(TODAY(),(1+($A2="YR"))*-12)+30))
You results should be similar to the following.
     

Summarize data in Excel with VBA

I have a table in Excel with dates and values. Every day there were a number of different values.
I want to summarize how many of each value there were every day.
Example:
From this
Date Value
10/1 Blue
10/1 Blue
10/1 Red
11/1 Blue
11/1 Blue
I want to get a new table with something like this:
10/1 11/1
Blue 2 2
Red 1 0
I'm convinced this is possible to do in VBA/Excel. Does anyone have any ideas?
Assuming the first table is in A1 and the second in E1, you could use a formula in F2 like:
=SUM(($A$2:$A$6=F$1)*($B$2:$B$6=$E2))
This is an array formula so you need to validate it by pressing CTRL+SHIFT+ENTER.
A2:A6 is the range with the dates, B2:B6 the range with the colors in your first table.
The first part of the formula says: Retain records where the value in column A is 10/1 ( = F1).
The second part says : Retain records where the value in column B is Blue ( = E2).
The '*' is equivalent to AND.
More about it here: Multiple conditions in excel 2002
The solution was, just as Alex K said, to use the Privot Table function included in Excel.
Thanks for your help!

Conditional formatting in Access

I have a datasheet that looks like this:
ID name_ 1 2 3 4
1 name1 x 0 0 0
2 name2 0 x 0 0
3 name3 0 0 x 0
4 name4 0 0 0 x
I have rectangles on a report that correspond to this datasheet.
When the report opens, I need the rectangles to be colored red according to the data. For example, in the name1 row where there is an x in the 1 column, I need the specific rectangle corresponding to this (name1, 1) to be colored red. Here is the result that I need:
x
x
x
x
(where x is a rectangle that is red)
Perhaps the best place to place this code would be in ON LOAD event of the report, but i am not sure exactly. Can you please suggest to me some code that would turn the specified rectangles red according to the data?
Use conditional formatting, not code.
In this case, I see no reason that #Remou's answer is not correct -- you want to display an x, which is data, so you would use a textbox with conditional formatting that sets the background color appropriately.
However, if you wanted to do this without a data control, you'd likely use the Format event of the Detail of the report. This is the event that fires when each record is processed, and it could be used to run a test that determines which rectangle to hide/show or what color to give the background of the rectangle.
The OnOpen runs before any of the data is loaded, and the OnLoad event before any particular rows are accessed. Because of that, neither is appropriate for formatting controls in individual rows of the report.
And BTW, your mention of the OnLoad in reports indicates that you're using Access 2007 or later (the event didn't exist for reports in A2003 and earlier), and you should have stated that in your question.