Formula syntax (Counting unique values with conditionals) - excel

I've got this formula
=COUNTA(UNIQUE(
FILTER($B$2:$B$10,
(($C$2:$C$10<DATEVALUE("1/5/2021"))*
($C$2:$C$10>=DATEVALUE("1/1/2021"))*
($A$2:$A$10=$F2)))))
and I want to modify it so I can use it with my own workbook references, but I keep getting a syntax error and I can't see where this is happening.
This is the formula I'm trying to create
=COUNTA(UNIQUE(
FILTER(MachineData!B:B,
((MachineData!C:C,">="&$Q$15-30)*
(MachineData!$C:$C,"<="&$Q$15+0.999988)*
(MachineData!N:N= $S$108)))))
Note: &$Q$15 has the date I'm referencing and I'm just trying to use the past month as my reference for the date ranges.

As I mentioned in comment try below formula-
=COUNTA(UNIQUE(FILTER(MachineData!B:B,((MachineData!C:C>=$Q$15-30)*(MachineData!$C:$C<=$Q$15+0.999988)*(MachineData!N:N=$S$108)))))

Related

Excel load the previous record allocated for the given cell value

Good afternoon,
I am wondering how to use i.e. the match function for the previous value allocated for the given record. In the image below I have got the "Matt" string in one column and the different address in another column.
I want to use sth like PREVIOUS MATCH function, when it's possible.
I found some possible solutions here:
https://www.extendoffice.com/documents/excel/2699-excel-vlookup-find-first-2nd-match.html
and regarding this incorporated the formula into my situation.
=INDEX($D$3:$D$9,SMALL(IF($D$8=$G$3:$G$9,ROW($A$2:$G$9)-ROW($G$3)+1),2))
I am getting #NUM instead.
Nevertheless of my error the formula regards to 1st, 2nd match and eventually the last one. I need something similar for the previous record.
Only what I could find so far is:
https://exceljet.net/keyboard-shortcuts/find-previous-match
but they're only the keyboard shortcuts.
I could also find the formula for first and last match:
https://exceljet.net/how-to-lookup-first-and-last-match
but not for the previous one.
I tried also:
=INDEX(IF($D$1:$D$20="Matt",$G$1:$G$20),MAX(IF($D$1:$D$20="Matt",ROW($G$1:$G$20))))
but I am getting #VALUE this time
UPLOAD:
My last approaching was the closest.
I used this formula:
=LOOKUP(2,1/($D$2:$D$14=$D$8),$H$2:$H$14)
based on the solution from here:
https://trumpexcel.com/find-last-occurrence/
and it works, but brings me the last record instead of previous(preultimate) one.
How can I do this?
Use the array formula:
=INDEX(D3:D9,LARGE(--(B3:B9="Matt")*ROW(INDIRECT("A1:A" & ROWS(B3:B9))),IF(COUNTIF(B3:B9,"Matt")>1,2,1)))
Press Ctrl+Shift+Enter.
I don't know which cell(s) you want to use this formula. So, please with absolution/relative references in the formula to suit your need.

Excel - Minimum and If statement - date error

I am trying to write a formula that checks the status and name to be ongoing and joe blogs (in this example), and once finding a match, will identify the oldest date of a ticket raised.
My formula currently includes:
=MIN(IF('Sheet2'!AA:AA="ONGOING",IF('Sheet2'!Q:Q="Joe Bloggs",'Sheet2'!B18:B49)))
I also tried:
=IF((AND(sheet2!$AA:$AA="ongoing", 'Sheet2'!$Q:$Q="Joe Bloggs")), MIN('Sheet2'!B18:B49),"No")
In Column B contains dates. Q contains names, AA contains the status.
At the moment when this runs I get the result '00/01/1990'.
I have done some checks to find the error, and appears to be around the targets name, as when the second formula is tried, the output is "no". The name is definitely in the Q column, and I have completed other formulas including countifs which have worked perfectly fine.
I have done a lot of searching to find nested ifs and min statements to have no joy , would be grateful of any advice / tips. It may be a simple error to some.
Try entering this as an array formula:
=MIN(IF(sheet2!AA:AA="ongoing",IF(sheet2!q:q="Joe Bloggs",sheet2!B:B)))
FYI I found the solution here.
You will have to apply a date format to the result.
Your first formula works well on my data (as below). If I close the formula with ENTER only, I get the result '37128' and if I close the formula with CTRL+SHIFT+ENTER I get the expected result, '25/08/2001'.
Edit: As #FocusWiz said in the comments, the only major difference (other than different column names) between my formula and yours is the the last range in your formula (B18:B49) is a different sized range to the other two, which are referring to full columns.
*This could be solved either by using the same row range for all three column references (AA18:AA49, Q18:Q49, B18:B49) or referencing the full column range for all three ranges (AA:AA,Q:Q,B:B).
This is your formula I'm talking about:
=MIN(IF('Sheet2'!AA:AA="ONGOING",IF('Sheet2'!Q:Q="Joe Bloggs",'Sheet2'!B18:B49)))
And this is the formula in my workbook F7:
=MIN(IF(B:B="ONGOING",IF(A:A="Joe Bloggs",C:C)))
As you can see in the formula editor, squiggly brackets '{}' show around the formula when it has been closed as an array formula.
If that doesn't work for you, please post some sample data with datatypes so we can help figure out what is causing the lookup value to miss the data.
While I like the technique offered by Patrick (I have frequently forgotten an "else" portion of a formula and gotten "false" as a value in a cell but never thought of a use for that...thank you!), I think this question highlights an issue we all can have with array formulas. As girlvsdata indicates, your original formula:
=MIN(IF(Sheet2!AA:AA="ONGOING",IF(Sheet2!Q:Q="Joe Bloggs",Sheet2!B:B)))
(modified above to be more generic for column B) will also work when entered as an array formula.
What likely happened is that somehow the formula got edited and was not re-entered as an array formula.
While I do not dislike array formulas, I do try to avoid them because I have fat fingers and will frequently mess them up by accidentally hitting the wrong key as I am modifying other cells.
Here is an alternative without using an array formula:
=INDEX(LARGE((Sheet2!Q:Q&Sheet2!AA:AA="Joe bloggs"&"ongoing")*(Sheet2!B:B),COUNTIFS(Sheet2!Q:Q,"Joe Bloggs",Sheet2!AA:AA,"ongoing")),1)
What it does is basically create a candidate date value for every row that has "joe bloggs" and "ongoing" which is equal to the date in column B for all such rows. All other rows get a zero candidate date value. The LARGE function takes the smallest nonzero date by counting the n valid candidates with the COUNTIFS function and taking the nth largest such candidate.

SUMIFS less than criteria in a table

I have a simple table in a workbook to track monthly spend per item. What I'd like to do is work out the cumulative spend per item - I know I can do that using SUMIFS() but I can't figure out the correct syntax.
Here's a screenshot of the workbook currently:
The formula for CumulativeSpend is
=SUMIFS([Spend],[Item],[#Item], [YearMonth], [#YearMonth])
however all that does is provide the same number as [#Spend]. What I need to do is sum up everything from [#Spend] where [YearMonth] is less than or equal to `[#YearMonth] but I can't figure out the syntax. I have tried all of the following:
=SUMIFS([Spend],[Item],[#Item], [YearMonth], <=[#YearMonth])
=SUMIFS([Spend],[Item],[#Item], [YearMonth], "<="[#YearMonth])
all of which are invalid formulae. I've also tried this:
=SUMIFS([Spend],[Item],[#Item], [YearMonth], "<=[#YearMonth]")
which is a valid formula but (unsurprisingly) it doesn't give the right answer.
A read-only copy of the workbook I've used here can be accessed at: https://1drv.ms/x/s!AjcmU60daA9VquZIhFGJlUyysNmFCw
Can anyone give me the formula to calculate the CumulativeSpend per item per month?
You need to concatenate the string with &:
=SUMIFS([Spend],[Item],[#Item], [YearMonth], "<=" & [#YearMonth])
Ah, immediately after posting this I figured it out!
=SUMIFS([Spend],[Item],[#Item], [YearMonth], "<="&[#YearMonth])

Dynamically extract a list of unique values from a column range in Excel?

I found this example in an excel tutorial
The following image is my desired result. and the following formula is supposed to be able to extract the unique records dynamically. I know how to do this with VBA but i really want to make this a formula without using a macro.
=IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$1:D1, $B$2:$B$9), 0)),"")
I have tried the above formula as given in the example link above but it returns with error. I am assuming that this worked at some point in excel however it no longer works with Excel 2016. Can someone clarify why this formula no longer works? Thank you.
Answering my own question about 5 minutes later, so i read the patch nodes on the how match changed from excel 2008 to 2016. You need to use the index rather than the count.
=IFERROR(INDEX($B$2:$B$9, MATCH(0,INDEX(COUNTIF($D$1:D1,$B$2:$B$9),0,0),0)),"0)),"")")
Recommended edit to the formula to change the value returned on error to a blank:
=IFERROR(INDEX($B$2:$B$9, MATCH(0,INDEX(COUNTIF($D$1:D1,$B$2:$B$9),0,0),0)),"")

Using Sumproduct with ranges and cell references

I am attempting to use sumproduct in replace of sumifs so I can use multiple criteria within a single range. What works so far is:
=SUMPRODUCT(Table2[Sum of MKTValue],--ISNUMBER(MATCH(Table2[Code],{"EG1","EG2"},0)),--ISNUMBER(MATCH(Table2[Currency],{"GBP","USD","EUR"},0)),(Table2[Final Date]=INDIRECT("J"&SUM(ROW()-102)))*1)
However I need the "J" column reference, when I attempt to drive this using the current column as below:
=SUMPRODUCT(Table2[Sum of MKTValue],--ISNUMBER(MATCH(Table2[Code],{"EG1","EG2"},0)),--ISNUMBER(MATCH(Table2[Currency],{"GBP","USD","EUR"},0)),(Table2[Final Date]=INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","")&SUM(ROW()-102)))*1)
Then I am getting a #VALUE error. I have tried a number of different varieties of the above but I cannot get it to work.
Thanks for your help.
I assume that Jn contains a valid date - try moving the SUM function to outside INDIRECT, i.e. with last criterion
(Table2[Final Date]=SUM(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","")&ROW()-102))*1

Resources