I am trying to simplify a process of counting how many of a specified criteria are in a table.
What I need is to count the number of items that meet all of the following criteria:
[BusinessArea] = "Corporate"
[Application] = "CS"
[Status] = "Resolved"
[ResolvedDate] = *if the resolved date is between DateA and DateB eon a
separate worksheet.
I can do it using VBA or Formulas but I just cannot figure out the date part. I have them figured out separately as:
=IF(AND(Sheet1!I71 >= (TODAY()-7), Sheet1!I71 <TODAY()), TRUE, FALSE)
Where i71 is the [ResolvedDate] (it is searching just this one entry without the other filters.
=COUNTIFS(Table8[Business Area], "Corporate", Table8[Application], "CS")
Where it counts the number of entries that are Corporate_CS entries.
What I currently have:
'=COUNTIFS(Table8[Reported Date],AND(Table8[Reported Date]<='Ticket Summary'!F61, Table8[Reported Date]< TODAY()),Table8[Business Area], "Corporate", Table8[Application], "CS")'
Where F61 is a previous date (beginning of range)
Of which it is returning 9 instead of 6. There are 9 entries that match the criteria, 6 matching the date range and criteria
Try this:
=COUNTIFS(Table8[BusinessArea], "Corporate", Table8[Application], "CS",Table8[Status], "Resolved", Table8[ResolvedDate], ">=" & I61, Table8[ResolvedDate], "< " & I71)
I'm assuming that I61 is the start date and I71 is the end date.
I used this as a guide for the dates: count-cells-between-dates
Multi-criteria counting is a little tough in Excel. I used to make extra columns and concatenate values. Then you can use countif without too much trouble. But it was messy. You could also use DCOUNTA by setting up your query parameters on another part of your sheet (but it doesn't like tables - only cell ranges). Again, its a little messy, but it's very flexible.
My preferred method is to use the SUMPRODUCT function. Everything can be done in one formula and it works with tables. To get your count using SUMPRODUCT:
=SUMPRODUCT((Table8[BusinessArea]="Corporate")*(Table8[Application]="CS")*(Table8[Status]="Resolved")*(Table8[ResolvedDate]>DateA)*(Table8[ResolvedDate]<DateB))
Related
I have a Table with a column that I added, that checks the date of that row against a formula.
The result of that formulae is TRUE or FALSE and a subsequent Pivot Table Sums a value in the TRUE rows. I Introduced it to get what is called a Rolling Total Income.
There are two formula and I want to swap from one to another using VBA.
The formula are:
=IF([#Date] = "", "", AND([#Date]>=EOMONTH(TODAY(),-13)+1,[#Date]<EOMONTH(TODAY(),-1)))
for the Rolling data.
=IF(AND([#Date] >=G1,[#Date] <=H1),"TRUE","FALSE")
for the Sum of Income between G1 and H1, the financial year start and end dates.
The VBA I have tried is as follows:
Set lo = Sheet2.ListObjects(1) 'Sheet2 is the Income sheet see Project list
lo.Parent.Activate 'Activate sheet that Table is on
Set lColName = lo.ListColumns(9)
lColName.DataBodyRange.Cells(1).Formula = [=IF(AND([#Date] >=G1,[#Date] <=H1),"TRUE","FALSE")]
Running the above errors and gives #VALUE in the first cell in that column, and doesn't ripple through the rest of the column.
What have I done wrong?
Try
lColName.DataBodyRange.Formula = "=IF(AND([#Date] >=$G$1,[#Date] <=$H$1),""TRUE"",""FALSE"")"
Thanks, those changes have sorted it.
One more refinement I am struggling with.
The IF test statement is testing a date against cells, $G1 and $H1 which I set up for ease of debugging. However I have another worksheet in the workbook where I store all the references/static data I use in the various Sheets and I have placed those dates there. In this Module, before the IF statement, I have set those dates against two variables.
startdate = Range("I2").Value
enddate = Range("J2").Value
I now want to use those in the IF statement but cannot get the correct syntax!
This just errors:
"=IF(AND([#Date] >= startdate,[#Date] <= enddate),""TRUE"",""FALSE"")"
How should I write it?
Thanks
I have criteria ranges (C3:C9, I4:I9, O4:O9) which I would like to use in my countifs statement. Doing one range on its own works as expected. But as soon as I add more than one range into the countif statement it returns a NULL value.
Due to the layout of the spreadsheet these values are the same just split across 3 ranges.
The spreadsheet should help me view times teams are going on lunch. And i have a working model. Just need help working with Multiple Data ranges in Countifs
Tried using a single Data set - Works as expected
Tried all sets singular. They also work as intended.
=COUNTIFS($C4:C$9, "<=" & A12,$E4:$E9,">" & A12) Works Single Criteria Range)
Works Single Criteria Range)
=COUNTIFS($C4:C$9 $I$4:$I$8 $O$4:$O$9, "<=" & A12,$E4:$E9,">" & A12)
NULL Value Does not work.
The Expected output would be for all data ranges to be accepted and not return a null value.
You might want to consider using SUMPRODUCT(), here is an example:
The formula I used translates to:
=SUMPRODUCT(((A1:A11<=A12)*(A1:A11<>"")*(C1:C11>A12))+((D1:D11<=A12)*(D1:D11<>"")*(F1:F11>A12)))
You can extend the formula with more ranges obviously. In your case it would look like:
=SUMPRODUCT(((C4:C9<=A12)*(C4:C9<>"")*(E4:E9>A12))+((I4:I9<=A12)*(I4:I9<>"")*(K4:K9>A12))+((O4:O9<=A12)*(O4:O9<>"")*(Q4:Q9>A12)))
This is my first post and I can't find an exact answer anywhere. I have an Excel spreadsheet that is becoming too large to operate because I have long formulas in millions of cells. I need to know how to calculate the formula using VBA but have only the value appear in Excel. An example is I want to multiply column B by column C:
I have tried this code:
Range("D3:D6").Formula = Evaluate("=B3*C3")
It correctly calculates for the first cell, but for the other cells it still tries to calculate B3*C3 as a fixed reference rather than as a dynamic references that changes as the cell position changes.
How could I fix this? Thankyou.
Edit:
My actual spreadsheet looks like this:
This formula needs to be applied down 17520 rows and across 300 columns, but I only want the values to appear in Excel. The purpose of this is to reduce file size and reduce calculation time.
=IF(-SUMIF(AIG$4:AIG4,"<0")>0.9*SUMIF(AIG$4:AIG4,">0"),0,IF(-SUMIF(AIG$4:AIG4,"<0")-IF(WQ5<'Battery Specs'!$B$13,-'Battery Specs'!$B$15,IF(WQ5=ROUNDDOWN('Battery Specs'!$B$13,0)+1,-('Battery Specs'!$B$13-ROUNDDOWN('Battery Specs'!$B$13,0))*'Battery Specs'!$B$15,0))>0.9*SUMIF(AIG$4:AIG4,">0"),-(0.9*SUMIF(AIG$4:AIG4,">0")+SUMIF(AIG$4:AIG4,"<0")),IF(WQ5<'Battery Specs'!$B$13,-'Battery Specs'!$B$15,IF(WQ5=ROUNDDOWN('Battery Specs'!$B$13,0)+1,-('Battery Specs'!$B$13-ROUNDDOWN('Battery Specs'!$B$13,0))*'Battery Specs'!$B$15,IF((0.9*SUMIF(AIG$4:AIG4,">0")+SUMIF(AIG$4:AIG4,"<0"))>'Battery Specs'!$B$10,0,IF(((0.9*SUMIF(AIG$4:AIG4,">0")+SUMIF(AIG$4:AIG4,"<0"))+$AIF5*0.9)>'Battery Specs'!$B$10,'Battery Specs'!$B$10-(0.9*SUMIF(AIG$4:AIG4,">0")+SUMIF(AIG$4:AIG4,"<0")),$AIF5))))))
Try
Range("D3:D6").Formula = "=B3*C3"
Range("D3:D6").Value = Range("D3:D6").Value
or simply
Range("D3:D6").Formula = Evaluate("(B3:B6)*(C3:C6)")
Using Evaluate to calculate the formulas and then transfer the values to Excel will be slower than having Excel calculate the formulas directly.
Here are a couple of things you could try:
a) Formulas
You only have 5 million formulas in 5 million cells - this is not an overwhelmingly large number but your formulas are very long and each formula references a large number of cells.
Your formula contains many repeated expressions and calculations - move them out to helper cells and try to simplify/shorten your formula.
b) VBA - don't use Evaluate - just grab the range of 5 million cells into a single variant array and use VBA Loops, arithmetic and logic to accomplish the same task as your formulas and then put the array back.
I believe best option is to keep formulas instead of using VBA to produce same formulas. Instead, when entering new data in SpreadSheet, be sure to set calculations to manual (go to Formulas tab=>Calculation Options=>Manual. This way you wont trigger calculations when entering/pasting new values, meaning your Excel file will operate just as fast as if there was no formulas. After you entered/pasted all new values, set Calculations to Automatic.
You might want to try this:
Dim i as Integer
For i = 3 to 6
Range("D" & i).Value = Range("B" & i).Value * Range("C" & i).Value
Next i
The other alternative is to name your formula, for instance, instead of saying =B3*C3, you can give it a name say times value, and then say =timesvalue. Next, remove the formula and leave the value only. E.g. range("D3:D30").value=range("D3:D30").value
I have months in my column header and I want Excel to Fill them in sequentially. It currently does this by default but it is filling in the long month even though it understands my short month.
Eg: I manually wrote in 'Sep' for September but it fills 'October' in the next column instead of 'Oct.'
I know Excel has both versions of months stored in it's default Custom Lists. How do I get it to switch?
You can use this formula :
=Text(A1,"mmm")
Where A1 is the cell/column/row, thus u can change it to your requirements.
After typing that formula drag it along the following rows and it will apply the formula accordingly.
Also for further refrence and/or questions u may also check this.
You can use this Formula in VBA to fill the rest of the months:
[A1] = "May"
[B1:L1].Formula = "=TEXT((A1 & "" 1"") + 50, ""mmm"")"
[B1:L1] = [B1:L1].Value2 ' optional to convert the formulas to values
I trying to create dynamic report out of a work sheet I have and I am kind of stuck not able to get unique values.
In A1:A15000k I have Ticket/Task#, the ticket can be worked on more than once, i am trying to apply another criteria to my formula to only allow unique Ticket numbers to be counted.
here is the formula i am using now:
=SUMPRODUCT(COUNTIFS(INDIRECT($C$3 & "!$G$1:$G$14989"),INDIRECT(D3),INDIRECT($C$3 & "!$S$1:$S$14989"),$B$3, INDIRECT($C$3 & "!$H$1:$H$14989"), E$10, INDIRECT($C$3 & "!$U$1:$U$14989"), ">="& $C$7, INDIRECT($C$3 & "!$U$1:$U$14989"), "<="& $D$7))
Non dynamic version of it
=SUMPRODUCT(COUNTIFS($G$1:$G$14989,Names, $H$1:$H$14989, "Priority", $N$1:$N$14989, ">=3/15/2016", $N$1:$N$14989, "<=3/16/2017"))
where Names represent a set of users....
I gut this finally working but with a helper column... just added a new column to my original sheet that is checking duplicates n the column i don't want to count when its duplicated
=IF(COUNTIF($C$6:$C6,C6)>1,"DUPLICATE",1)
After that all i needed to do a dd the new column to my countifs formula...