Complex conditional - conditional-statements

I have the following sheet called DailyReport:
I am currently calculating Column M with:
=SUMPRODUCT(A2:A200=A2, G2:G200)
Then on a secondary sheet I have the following second sheet WeeklyReport:
Now what I want to do is, if WeeklyReport Column A2 == DailyReport Column A, then take the date in DailyReport Column B and test it to fall in the date range in WeeklyReport Column B and Column C with:
=IF(AND(DailyReport.B2>=B2,DailyReport.B2<=C2),1, 0)
and if that is true add the Total Daily Hours to the total in WeeklyReports Column D from DailyReports Column M.

I think summing values from column M, which is itself a sum, would not meet the goal. Summing sums would make too big a value, and column M is not filtered by date, so numbers from the wrong dates would be included.
I like better the idea of extending the way you used SUMPRODUCT to get the column M numbers. Instead of just checking for a matching name, add two more parameters to check for a date later or equal to the "Week Start Date" and earlier or equal to the "Week End Date".
So three true/false or 1/0 parameters (where multiplying by 1 for true keeps the value and multiplying by 0 for false removes the value) and the fourth parameter of the hour values to be summed:
=SUMPRODUCT(DailyReport.A$2:A$200=A2, DailyReport.B$2:B$200>=B2, DailyReport.B$2:‌​B$200<=C2, DailyReport.G$2:G$200)
The poster also came very close to a solution using SUMIFS (in the comments). The default condition test is =, but for the date comparisons we want to use greater than and less than operators. The LibreOffice/OpenOffice syntax for this is to put the relational operators in double quotes, then use & to connect them to the cell address that contains the test value:
=SUMIFS(DailyReport.G$2:G$200, DailyReport.A$2:A$200, A2, DailyReport.B$2:B$200, ">=" & B2, DailyReport.B$2:B$200, "<=" & C2)
In both these cases I have included $ signs to make the row numbers absolute. Absolute cell addresses will not change if the formula is copy-pasted; in this case the copy-paste might be over multiple rows on the WeeklyReport sheet to get hour totals for multiple people.

Related

Extracting "hidden" data from expanding/collapsing pivot table - Excel

I'm not sure if this is possible but as you can see I have a pivot table with multiple dependent and expandable fields. I am trying to concatenate the data from columns A:D into one cell which works fine in row 2 but doesn't work with blank parent cells, as you can see in column F.
Any ideas for how to achieve this?
Pivot table
This answer assumes that you don't want to just Repeat All Item Labels in the PivotTable from the "Report Layout" drop-down on the Pivt Table Tools "Design" tab.
A formula to get the first non-blank value on or above the same row as the current cell from Column B can be constructed with a combination of AGGREGATE, SUMPRODUCT and OFFSET, like so:
=OFFSET($B2,SUMPRODUCT(AGGREGATE(14,6,ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0),1))-ROW(),0)
How does it work?
Starting with the outermost part, OFFSET($B2, VALUE, 0) - this will start in cell B2, then look up or down by VALUE rows to get the value.
Next we need to know how many rows we will need to look up-or-down. Now, if we can work out the bottom-most row with data, we can subtract the current ROW() from that, giving us OFFSET($B2, NON_BLANK-ROW(),0)
So, to finish up we need to work out which rows are not blank, AND which rows are on-or-above our current row, then take the largest of those. This is going to take an ArrayFormula, but we can use SUMPRODUCT to make that calculate properly. To find the largest number we could use MAX or LARGE - but we get less errors if we pick AGGREGATE(14,6,..,1). (The 14 means "we want the kth largest number", the 6 means "ignore error values", and the 1 is k - so "we want the largest number, ignoring errors")
But, what list of numbers are we going to look at, I don't hear you ask. Well, we want the ROW for output from our range (I'm using $B$1:$B$100, because using the whole column B would take far to long to calculate repeatedly), a comparison against the current ROW(), and check that the LENgth is > 0. Those last two are comparisons, so let's write them out first:
ROW($B$1:$B100)<=ROW()
and
LEN($B$1:$B$100)>0
We want to use -- to convert TRUE and FALSE to 1 and 0 - this means that any "bad" values become 0, and any "good" values are larger than 0:
ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0)
This gives us the Row number when the Row is on-or-before the current row AND Column B is not blank - if either of those are False, then we get 0 instead. Stick that in the AGGREGATE to find the largest number:
AGGREGATE(14, 6, ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0), 1)
Then put it in a SUMPRODUCT to force Excel to treat it as an ArrayFormula, and that's your NON_BLANK. This then gives you that first formula right at the top of the post

Excel 2013 conditional formatting using a formula

I have a spreadsheet in Excel 2013 with Location in Column A, Material Number in Column B and types or groups of materials sorted by material number in Column I J & K. Other columns contain data that is irrelevant here.
Column B can contain the same material number in multiple cells.
I'm trying to find a simpler way to format font and color of the items in Column B by comparing if the item is located in Column I J or K, or not at all (no formatting in that case).
I was entering an individual conditional rule to compare Column B with the value in cell I3, another rule for I4, another rule for I5 and so on.
This is getting unwieldy due to the number of items now in I J & K.
There has to be a simpler, more elegant way to do this. Conditional formatting using exact match is not letting me select a range of cells for the match value.
I just need to format the text in Column B to Bold and Blue if the number exists in Column I also, or Bold and Red if it exists in Column J or Bold and Green if it exists in Column K.
Set up a conditional formatting rule that uses a formula. The formula can contain a Countif function that counts how many times the value in cell B in the current row is counted in column I. For example, starting in row 2, select B2 and add a formatting rule with the formula
=COUNTIF($I:$I,$B2)
Take care to use the current row number in the formula and don't use a dollar sign $ in front of the row number. Set three rules, one for column I, one for J and another one for K.
You don't need a new set of rules for each row. Just apply the three rules to all the rows required.

Using CONCATENATE to populate a sum formula in excel vba

I have a spreadsheet that has numbers for a particular year and then subtotals for that year.
The number of instances in a year can vary and there may be a year that doesn't exist i.e., 2018 might be skipped. The title of the totals row is always "FYXX Totals." I have a for loop that goes through the entire column and looks for "FY" Then if it falls within one of three categories (FY1-FY2, FY3-FY7, FY3-FY9; these being variables that represent a year). What I need is for the loop to sum the number in column D, E, F...when "FY" is found. I think using CONCATENATE might be the way to go but I am not sure a) exactly how to do that or b) if that is even the best way to go about it.
Dim rng As Range
Dim SumRow As Integer
Set rng = Range("C4:C" & NextRow)
For Each cell In rng
If Left(cell.Value, 2) = "FY" Then
If 2000 + Int(Mid(cell.Value, 3, 2)) <= FY2 Then 'This is the if statement for the fisrt category
'Here would be the sum function when the if statement is triggered
End If
End If
Next cell
Thanks so much for the help.
SpreadSheet_Picture
The second if loop (right now written for the first category) would need to sum the just the zero that is in column D next to FY17 Total. Keep in mind that sometimes row for FY18 may exist so this macro would have to be able to grab that as well should it exist. But in this case what would have to go into cell "D" & NextRow would be =SUM(D5).
My best attempt at understanding what you're after is that you want to place a formula in each cell of column D where the cell in column C contains FYxx Total, where xx meets certain other criteria. That formula should contain the sum of all the cells in column D for which the cell in the corresponding row of column C contains the same value of FYxx.
The easiest way I can think of to achieve this is to use the SUMIF function:
The formula =SUMIF(B$2:B$999,LEFT(C3,4),D$2:D$999) in cell D3 calculates the sum of all cells in column D where the cell in the corresponding row of column B matches the criterion, i.e. is equal to the first four characters of cell C3.
Unless there are further instances of the same FYxx value elsewhere in column B, the ranges in the first and third arguments of the SUMIF can cover the whole table, which I've assumed here extends to row 999, so you can keep those the same for each cell you place this formula in. You only need to change the row for the cell in column C in the second argument.
In fact if you really want, you can place exactly the same formula in each Total cell in column D:
=SUMIF(B$2:B$999,LEFT(INDEX(C$2:C$999,ROW()-1),4),D$2:D$999)
Here the INDEX function looks up the appropriate cell in column C based on the row of the cell that the function is placed in.

Count IF multiple criteria/data types match

I'm looking to generate a report to list the number of Cities/Towns that don't meet a certain criteria so on Sheet 2 I have an alphabetical list of all the cities/towns.
I want to do a look up/count if function to state if A2(Sheet 2) can be found anywhere in Column D on Sheet 1 then count it if the date in column L (sheet 1) matches the date in Cell $E$1 (sheet 2) and Column A in Sheet 1 is greater than zero.
I originally done this formula but it is returning an error.
=COUNTIFS(PickData!D:D,Sheet1!A2,PickData!L:L,Sheet1!$E$1,PickData!A:A,PickData!A:A>0)
Is there any other formulas that I'm currently not thinking of? Or is it possible to do this via VBA and it returns the value in to column B either True if it matches or False if it doesn't?
Thanks
Al
The problem with your previous formula is in the final criteria. Update to:
=COUNTIFS(PickData!D:D,Sheet1!A2,PickData!L:L,Sheet1!E2,PickData!A:A,">0")

Counting multiple criteria

I'm trying to count multiple criteria and got the code to work somehow with SUMPRODUCT.
Range("i2") = [SUMPRODUCT(($CZ$2:$CZ$61410="condition 1")*($DD$2:$DD$61410="condition 2")*($CU$2:$CU$61410=$A$2 <-/date/)*($CY$2:$CY$61410="condition 3"))]
There's around 40 colums with different conditions. So I have to code for each condition. But that's not really working for me, because I have to do the same thing for the whole month.
Explanation
Cells A2 to A32 hold dates, let's say from 1st of August 'til 31 of August.
Raw data table (on the same sheet) has dates on the CU column (might be 60000+ lines).
Column CZ, DD, CY, etc. have conditions that have to be met to be counted.
Question
What I want to do is if the date in column CU = the date in A2 then it will be counted to row 2, if the date in column CU = the date in A3 then it will be counted to row 3.
That way I can write one code for the whole month, not each day separately.
I offer first a solution of a formula (WorksheetFunction if preferred) of this type:
=COUNTIFS(CZ:CZ,"=1",DD:DD,"=2",CY:CY,"=3", ... CU:CU,"="&A2)
and an image showing what this results in (the yellow cell) depending upon the date chosen:
This counts the number of instances, on the date chosen in A2, that match the hard-coded criteria displayed in Row1 for illustrative purposes.
Without the hard-coding of criteria but with possibly a slightly better 'match' to the OP and with more examples:
Apart from the highlighting, the contents of C6 were entered via the following macro:
Sub Macro1()
Range("C6").Select
ActiveCell.FormulaR1C1 = "=COUNTIFS(C[101],R1C[101],C[105],R1C[105],C[100],R1C[100],C[96],""=""&RC[-2])"
End Sub