Using offset to create a dynamic range - vba

I currently have a column, which starts at B28 (The title) and from B29 Values.
I add data to the column using a macro, and calculate the mean and standard deviation of the profit figures. Since i add data, I can't just select for example B29:B10000 as it will skew any mean and standard deviation, as it will also take into account blank cells. Therefore, I need to create a range, which will update when data is added and will only range from the first to last numerical figure, no blank cells.
The current formula I use which does not work:
=OFFSET('Panel'!$B$28,1,0,COUNTA('Panel'!$B28:$B999)-1,1)
(also tried selecting the whole column $B:$B but did not work)
Is there any solution for this?
Cheers

yes. Convert the range to table.
Use normal formula e.g. from average(B2:B9) to average(tablename[Profit])
Before Year 8 is added
After Year 8 is added - auto update

Related

Conditional cell formatting on SSRS pivot table

I created a pivot table in SQL that has report names along the left side, and hours (00:00, 00:01, etc.) along the top. The values in the table are the number of times each report has been used during that hour over the past three months. I've imported the table into SSRS, and I'm trying to create a heat map of sorts. I want to color the cells darker or lighter across the row based on the number in each cell compared to the value of cells across the row (cell that has the highest value will be the darkest colored).
I've tried following this guide to color the cells, but here the entire row is one field, while I have separate fields for each column. Is there a way to achieve this?
EDIT: Added picture of table design, and preview where coloring is done incorrectly
I understand your problem better now...The function uses the min and max values of a column to determine the range from lightest to darkest, then it probably looks at what fraction of the range your actual value is. In your case where you have each column's data coming from a different cell it'll be a pain unless your columns are fixed and even then it's more trouble than it needs to be.
I would suggest the following.
DON'T PIVOT your data in SQL, we can do that really easily in SSRS, your dataset will be simpler too something like
ReportName Hour UsageCount
ReportA 0 8
ReportA 1 4
ReportC 22 18
and so on...
Create a new report and add a matrix with reportName as the row group and hour as the column group. The data values will be UsageCount.
That's it for the report design, then just set the cells back ground based on your function but this time you can pass in Max(Fields!UsageCount.Value) etc as per the sample.
I've rushed this a bit so it if not clear, let me know and I'll post a clearer solution.

How to color a cell based on values and date difference in another cell using VBA

Consider I have a Table A in Excel - details as below:
And another Table B as follows
I want out-put as follows,
The Name from Table B has to be checked with Name in Table A, and respective StartDate and EndDate should be picked from Table A and same should be compared with dates in Table B and cell under that name should be colored to green if Status in Table A is in "In Progress" or to Red if in "On hold"
For Example:
Consider Jack in Table B, it has 3 records in Table A, The first start date should be picked i.e 4-Apr-2017 and End date as 27-Apr-2017, and respective coloring has to be done based on status field.
How can I achieve this using VBA/anything in Excel. I'm new to VBA.
Yes you can do it in VBA but I would recommend using conditional formatting (formula) as it doesn't require programming knowledge. To do this, you will need to employ the Vlookup formula.
I believe the output you want is something in the picture link here?
To make conditional formatting, look in the "Home" tab, under Styles -> Conditional Formatting. Highlight the cell you want to format, then select Conditional Formatting -> New Rule. This will cause a new window to pop up. Select "Use a formula to determine which cells to format".
You would want 2 conditional formats.
1.To show green if the date is within the start and end date. To do so, select the first cell in the Gantt chart (cell B8 in example) then enter formula below.
=IF(AND(B$7>=VLOOKUP($A8,$A$2:$D$5,3,FALSE()),B$7<=VLOOKUP($A8,$A$2:$D$5,4,FALSE())),TRUE(),FALSE())
2.To show red when user has item beyond due date, enter formula below with same cell highlighted.
=IF(B$7>VLOOKUP($A8,$A$2:$D$5,4,FALSE()),TRUE(),FALSE())
Once that is done, you can apply the format painter or copy and paste the cell with conditional formatting to extend your table/Gantt chart.
Note that the $ signs are important as they lock the relative reference positions in the formulas. Using the second formula as an example, B$7 refers to the date and you need the reference to be locked to row 7, where all the dates are. On the other hand, the column reference (Column B) can be shifted as you want it to change to with the columns to properly compare against the other dates.
As for multiple items per user, can you expand upon your initial question? Would you like to track based on per user or per item? I am assuming that you're creating a Gantt chart to track a project. In that case, it would make more sense to track specific tasks assigned to people. You can modify the example given to track based on task.

Vertical line showing current week in timeline

Ok so I recently added a vertical line showing the current week in a chart using this method: http://www.officetooltips.com/excel/tips/how_to_add_a_vertical_line_to_the_chart.html
but now I want to add one to a sheet without a chart. Is this possible?
So my timeline looks like this:
Is vba needed or is this possible with formulas I really have no idea.
You can make it auto update every week using NOW() formula:
What you have to make sure is that each column is formatted based on the cell in row A (or any other row/column) so you format all cells based on the dates in the first row. To look from each cell to the second row you use OFFSET($A$1,1,COLUMN()-1) and get the relevant date for this column. This could be done for any other cell that holds the relevant date for the column, but there must be one like this. The condition in the figure is one for all the table.
EDIT:
To match the format of YYMM for the date, use the formula (assuming $D$2 is the upper left cell of the table):
=OFFSET($D$1,1,COLUMN()-COLUMN($D$1))=RIGHT(YEAR(NOW()),2)*100+WEEKNUM(NOW())
for the current week, or replace the NOW() in it with a cell with the date of interest.
Hope it solves your problem ;)

OpenRefine - Fill between cells but not at the end of the list

I have a list of stock prices for several stocks. Some of the values are missing due to weekends, holidays and probably other reasons.
The gaps are not consistent. Some are two days and some are more than that.
I want to fill the gaps with the last known value but not at the end of the list.
I have tried in Excel to test a few cells below and if it's now empty, do the fill. The problem is that due to the inconsistency of the gaps, it's a tedious task to change the function for all the cases.
Is there a way to test for the end of a list?
UPDATE - added a screenshot.
See this screenshot. I want to fill where the blue dots are. The red dots are at the end of the list and I don't want to fill those cells.
I am looking for a way to detect the end of the list and stop the filling when the end is detected.
I think this is pretty difficult in OpenRefine and probably a different tool would work better. The main issue is that OpenRefine does not offer the ability to easily work across rows so 'summing a column' (or part of a column) is tricky - this is mentioned in https://github.com/OpenRefine/OpenRefine/issues/200
However, you can do this by forcing OpenRefine in Record mode with the whole project containing a single record. Once you've done this you can access all values in a column using syntax like:
row.record.cells["Column name"].value
This gives an array of all the non-blank values in the column. Since this ignores blank values, in order to have a true view of the values in the column you have to fill in blank cells with a value.
So I think you could probably achieve what you want as follows:
For each column you are going to work with do a cell transform to put a dummy value in empty cells - e.g. if(isBlank(value),"null",value)
Create a new column at the start of your project and put a single value in the very first cell in that column
Switch to Record mode
At this point you should have a single 'Record' in your project - e.g.
You can now access all cells in a column using syntax like row.record.cells["Column 1"].value. You can combine this with 'forRange' to iterate through the contents of this array, using the row.index as the marker for the current row.
I used the following formula to add a new column to the project:
with(row.record.cells["Column 1"].value,w,if(forRange(row.index,w.length(),1,i,w[i].toNumber()).sum()>0,"a","b"))
Then...
Change back to 'Row' mode
Remove the 'null' placeholder from the original column
Create a facet on the 'fill filter' column
In my case I filter to 'a'
Use the 'fill down' option
Remove the filter
And remove the 'record' column
Rather a long winded way of doing it to say the least, but so far I've not been able to find anything better while not going outside OpenRefine. I'm guessing you could probably compress steps 5-11 into a single step or smaller number of steps.
If you want to access the array of cell values using Jython as suggested by iMitwe you need to use:
row["record"]["cells"]["Column 1"]["value"]
instead of
row.record.cells["Column 1"].value
(step 5)
I am doing this on the top of my head, but I think your best chance my be using the fill down option in record mode:
first move your column to the first column and switch to record mode.
then use the following GREL: row.record.cells["data"].value[-1] where data is the name of your column
The [-1] will take the last value and fill the blank. For the case with the red dot, since there is no value it should remains empty. Let us know how it goes.
Unless there's something I am missing or not seeing...
I would have just sorted reverse (date ascending) on the Date column, then individually use Fill Down on each column, except for that last column where you could then use a Date facet on your column Date to specify the exact Date range you wanted to work with, then fill down on that last column, then remove the Date range facet.

Excel: SUMing values that fall in a range (Extending SUMIFS to use ranges of Criteria)

First post - please be gentle.
I have an interesting problem where I'm trying to convert a flat data table into a cumulative total based on two ranges (to create cumulative graphs of progress). Something that should be really easy to do.
I've managed to collate the data into a summary table (effectively a pivot table but for layout and charting purposes I cant use an actual pivot table).
(I'm too new to post images - sorry its not embedded)
Screenshot
In this screenshot I'm trying to show the 3 columns on the left as a Flat data table.
Columns A & B are text values that can be 'any' text (so I cant use wild cards).
Column C is the value I'd like to SUM.
Currently I'm using an SUMIFS statement to find the sum of the "Hours" when the "Week" label matches the values in "column A" and the "Department" label matches the value in "Column B".
I would like to change this equation to find the cumulative value for each week (so in this example cell G6 would be 14 - i.e. 4 from week 1 and 10 from week 2.)
I would like to try and avoid duplicating the entire table just to find the cumulative
All I really need to be able to do in this example is replace the equation in F5:
=SUMIFS($C$2:$C$15,$B$2:$B$15,$E5,$A$2:$A$15,F$4)
with
=SUMIFS($C$2:$C$15,$B$2:$B$15,$E5,$A$2:$A$15,$F$4:F$4)
eg Sum the hours of all the weeks that have come before. Again - i cant use wild cards and I cant use pivot tables.
I imagine I need to use some Array formulae but I cant find any online resources to help me.
Any help would be appreciated.
Your formula works in Cell F5, but in G5 just make it add F5.
F5 =SUMIFS($C:$C,$B:$B,$E5,$A:$A,F$4)
G5 =SUMIFS($C:$C,$B:$B,$E5,$A:$A,G$4)+F5
H5 =SUMIFS($C:$C,$B:$B,$E5,$A:$A,H$4)+G5
I5 =SUMIFS($C:$C,$B:$B,$E5,$A:$A,I$4)+H5
Also use the entire column reference A:A if you dont know the total number of rows.
If you cant do that you could make your read data into a table and then instead of the sum_range being some defined locations, you can use Table1[Week] = Column A instead.
Hope this helps
-Scheballs