COUNTIF Unique values - excel

I used this formula to find SKU counts in certain categories given multiple criteria:
=+COUNTIFS(Data!$AG:$AG, ">"&0,Data!$AO:$AO, "="&$A115,Data!$L:$L, "="&D$104,Data!$P:$P,$B$103)
I am able to find the SKU counts but it gives me the total SKU count, I believe because it now counts any SKU with inventory greater than 0 with my multiple criteria.
How can I change the formula to get the unique SKU count per division?
Column AG: Inventory
Column AO: Division Name
Column L: Month
Column P: Year
Column T: SKU Code(written out) - what I need to find unique values of.
Example here: dropbox.com/s/hxbt7hb9l8hf4w6/Sample%20Example.xlsx?dl=0

If you created a helper column on the input sheet with the formula (e.g. in BG2):
=1/COUNTIFS(T:T,T2,AG:AG,">0",AO:AO,AO2,L:L,L2,P:P,P2)
This means that if you had, for example, 5 times the SKU in one Division/Month/Year, you would get 1/5. Then, in the calculation sheet, replace your COUNTIFS with a SUMIFS (summing your new helper column, using same conditions). This will mean that your 5 duplicates (with 1/5 in the helper) get summed to 1 - i.e. 1 unique SKU
EDIT
Because there are some where there is no positive inventory, the count gives you 0 and you get a #DIV/0! error... so we can fix that with:
=IFERROR(1/COUNTIFS(T:T,T2,AG:AG,">0",AO:AO,AO2,L:L,L2,P:P,P2),0)
Then, in the Output-EOM Unique SKU Count sheet, in cell e.g. B6, use:
=SUMIFS(input!$BG:$BG,input!$AO:$AO,$A6,input!$L:$L,B$5,input!$P:$P,$B$4)

Related

To count the unique number of values based on criteria

Column A is the list of projects and column B is the markets. Both the columns have duplicate values.
In the below example I want to count the number of unique projects in the Hong Kong market. The answer should be 8. I need the formula to calculate the same
I don't have Office 365 so the unique function will not work and I cannot use pivot. Have to use a formula.
This is the sample data the actual list consists of multiple markets and projects of sample size 200. Excel version 2016.
=SUM(--(FREQUENCY(IF(ISNUMBER(SEARCH("Hong Kong",B2:B13)),MATCH(A2:A13,A2:A13,0)),ROW(A2:A13)-ROW(A2)+1)>0))
IF checks wether Hong Kong is part of the market in the ISNUMBER, SEARCH section. And returns TRUE (1) or FALSE (0).
The MATCH part returns the row numbers of the first match of each value it searches in column A. If a value is used more than once the match will return the row number of the first match for each value.
The ROW(range)-ROW(first_value_in_range)+1 returns a sequence of the count of rows in your range.
FREQUENCY checks the occurance of the row numbers from the match-function versus the sequence created from the rows-part. If it occurs more than once FREQUENCY returns the total count of occurrences for the first and returns 0 for any next occurrence.
Finally it's summer by each frequency >0.
As this is an array formula you need to confirm the formula with ctrl+shift+enter

Return cell's value based on its date range in Excel

I have a table with specific products and dates and I want to get the cost values that correspond to that date . The source table has a range of dates and not an actual match (that is my problem).
Here is the task: we are trying to fill column "Cost" based on Sheet 2
SHEET 1:
Product
Date
Cost
price
First
29/12/2021
result 1 (formula type X)
100
Second
05/01/2021
result 2 (formula type X)
200
The other Sheet has the date ranges with the desired results (selling prices), like this:
SHEET 2:
Product
Start Date
End Date
Cost
First
28/12/2020
03/01/2021
result 1
Second
04/01/2021
11/01/2021
result 2
PS. I have different costs for different products in the same date. So, we needed to also add a parameter that will match the Product from one sheet with the product of the other.
If the given Ranges both start at A1 and end at D3 then the following works in Sheet1!C2:
=INDEX(Sheet2!D:D,MATCH(1,(B2>Sheet2!B:B)*(B2<Sheet2!C:C)*(A2=Sheet2!A:A),0))
This is an array formula to be entered with ctrl + shift + enter
It Indexes sheet2 column D and searches for the first match where all mentioned condition are true (=1). Each condition produces 1 or 0 for each cell in the range and multiplies it by the result of the cell from the next range in the same row. If either of the conditions is false it multiplies by 0 resulting in 0.
If all conditions are true it will result in 1 (111).
The overall produces an array of {0,0,1,0,...} and the match function returns the N'th occurance of the first 1, which is equal to the row number of the conditions being true.
Since you mentioned tables I'm going to assume you mean a real Excel Table and not just cells formatted into a table like appearance.
Sheet 1 Table is named: tbl_ProductPrice
Sheet 2 Table is named: tbl_ProductCost
"Cost" column formula in sheet 1:
=SUMIFS(tbl_ProductCost[Cost],[Date],">="&tbl_ProductCost[Start Date],[Date],"<="&tbl_ProductCost[End Date])
Explanation
First SUMIFS parameter, "Cost" column, is what will be summed up if all criteria are true.
First IF:
Second parameter is the date criteria to check.
Third parameter is what to check against, is greater than or equal to start date.
Second IF:
Fourth parameter is the date again for the second if statement
Fifth parameter is checking if less than or equal to the end date.
Results:
EDIT
Based on your comment regarding multiple product entries for different date ranges I would go with the Index Match approach instead.
=INDEX(tbl_ProductCost[Cost],MATCH(1,([#Product]=tbl_ProductCost[Product])*([#Date]>=tbl_ProductCost[Start Date])*([#Date]<=tbl_ProductCost[End Date]),0))
Enter formula with Ctrl+Shift+Entersince it's an array formula.
I added in a product match as well since you indicated multiple date ranges for each product type.
Results

Use dynamic sum range and criteria range in SUMIFS

I'm using SUMIFS to calculate sales revenue of product X over a period of time. The problem is that all the sum range and the criteria ranges are dynamic since sales reps will add more rows to record new sales everyday. My formula looks like this:
=SUMIFS(Revenue!I5:I24,Revenue!F5:F24,"Product X",Revenue!B5:B24,">="&B3,Revenue!B5:B24,"<="&C3)
The starting row is row 5, and the last row that currently has data is row 24.
Revenue is the worksheet that contains the data. In this worksheet, column I is the revenue, column F is the product name, column B is the date that the revenue is recorded. B3 and C3 are the start and end date of the period.
When a sales rep records a new revenue, the last row that has data will become row 25, so my formula won't count it in. I tried to replaced 24 with 1000 hoping that it would count when new data was added beneath, but it returned #VALUE.
What should I do?
Thank you
Declare 3 dynamic ranges and use their names in your formula.
=IFERROR(SUMIFS(revenueI,revenueF,"Product X",revenueB,">="&B3,revenueB,"<="&C3),"")
Adding the names: Press Ctrl+F3 to open the name manager and then enter the 3 names
Name: revenueB
RefersTo=
OFFSET(Revenue!$B$5,0,0,COUNTA(Revenue!$B$5:$B$1048576),1)
Name: revenueF
RefersTo=
=OFFSET(Revenue!$F$5,0,0,COUNTA(Revenue!$F$5:$F$1048576),1)
Name: revenueI
RefersTo=
=OFFSET(Revenue!$I$5,0,0,COUNTA(Revenue!$I$5:$I$1048576),1)
1048576 is for the max number of rows in more recent versions of Excel. Adjust to the total number of rows for your Excel version.
Wrap in an IFERROR in case of errors e.g. if named ranges are off different length.

Need help in excel formula

1) I have two tables. 1st table contains data for more then 20,000 rows and 2nd table I already have the following columns details i.e. Region, Item, Number and I just have to get the Total value of the product from the 1st table
2) There are two types of prices in the 1st table . One is Retail Price and Another one is a Wholesale price
3) In each of the regions Rep, Item and Numbers are same in most of the cases, but the Total price is different
4) I am able to get the Total price details in 2nd table through vlookup formula (After concatinating the following columns i.e. Region, Item and Number from both the tables) wherever there is an account number for retail price
5) Currently I am manually updating "Total Price" details in 2nd table for Wholesale price which is taking lot of time.
Is it possible to build a formula to get the wholesale price details in the 2nd table, since there are more then one account number, but the price is same
If the wholesale price is the lowest price for the specific item, then you can find it with the formulas MIN and IF.
Based on your screen shot:
D is the column with the list of items
I5 is the cell with the item name for which you want to find the wholesale price
F is the column with the list of prices
If you enter the following formula in cell K5, it should find the lowest price for pencils
=MIN(IF(D:D=I5,F:F))
On this link, there is an explanation if you want to use multiple criteria.
http://www.contextures.com/excelminmaxfunction.html
try the sumifs function.
It takes multiple arguments and criteria. So it should look something like:
cell value at j5 = sumifs(f3:f23, b3:b23, h5, d3:d23, i5....)
you need to mark off which rows in your first table are wholesale selling. So it should be a column of some kind. Once you do that, let's say in column G, then you add onto the sumifs function...
, g3:g23, L5)
What you're doing is summing up all of the values in column F where h5 (region) matches in b3:b23, i5 (item) match in d3:d23, and where L5 (retail type) match in a new column g2:g23.
This will find all of the values that match that criteria exactly.
Vlookup is useful, but it's harder to scale IMO than the advanced if functions.
SUMIFS is probably the better way to go on this one, but as an alternative there is also SUMPRODUCT.
=SUMPRODUCT(($H3=$B$3:$B$20004)*($I3=$D$3:$D$20004)*($J3=$E$3:$E$20004)*($F$3:$F$20004))
The * acts as an AND statement in a logical check, and each of the ($H3=$B$3:$B$20004) is a logical check. When the row is true it will evaluate to 1. When it is false it will evaluate to 0. in the end you wind up with a list of prices or 0s that get summed. The end result is the sum of everything that matches your criteria.
The danger of using this formula is that it can get labour intensive as it is performing array calculations without being an array formula.

Trying to return topmost row in a lookup [duplicate]

This question already has answers here:
Return max index value in vlookup
(3 answers)
Closed 8 years ago.
I have a sheet that's full of prices, products, and locations. I currently have a MAX/IF formula that goes to this sheet, finds the product in col A, then returns the highest value from cols C:G. Now I need to have the next cell over display the location where that price originates.
Example:
A - B - C - D - E - F - G
1 - PRODS - ID - L1 - L2 - L3 - L4 - L5
2...
5 - Prod4 id1 $100 $125 $155 $110 $150
6...
Product: Prod4
Price: $155
Location: ???
So here I have a cell that says what product, then the price cell using MAX/IF statements gets to the highest price in col C:G after finding the product in col A. So how do I now return which location that price is in. The location box needs to have a formula to return (in this example) "L3" since it's the col that has the highest price. Row 1 is the headings so it will always have the value needed, but wont always been the same index from the price (because the row the price is in could change). I've tried making index/match work but can't seem to return an actual value when using it.
Edit:
This is a direct copy paste from my spreadsheet. Buy Averages is the name of the sheet where the products are listed. G15 is where the highest price is listed, F14 is where the name of the product is listed. I have several hundred products, but the likelihood of passing 1k isn't very high.
=INDEX('Buy Averages'!$C$1:$G$1,MATCH(G15,INDEX('Buy Averages'!$C$2:$G$1000,MATCH(F14,'Buy Averages'!$A$2:$A$1000,0),0),0))
You were on the right lines with Index and Match
first we need to find the max price - you already have that calculated, so I'll just use a placeholder of MAX(5:5)
Next, we need to find where that value is by using Match, which gives us MATCH(MAX(5:5),5:5,0), the zero because we require an exact match
Next we use that number in an index, with the first row as where we are searching, a row number of 1, and a column of the number we got from the Match:
=INDEX(1:1,1,MATCH(MAX(5:5),5:5,0))
if you are using a version of excel that is 2003 or before, you will have to replace the rows 1:1 with A1:GA1 (or however far the row runs), and the same for the other row references, changing only the row number
=INDEX(A1:GA1,1,MATCH(MAX(A5:GA5),A5:GA5,0))

Resources