How to use COUNTX to find number of occurences of variable - excel

This question pertains to PowerPivot.
I am currently designing an invoices table to include a column called "Hits", which counts the amount of times a single customer has purchased one item.
I currently have a table like so:
INVOICES
INVOICE ID CUSTOMER ID PRODUCT ID
321 1 444
322 2 411
323 3 221
324 4 321
325 5 444
326 5 444
This is what I would like it do look like:
INVOICES
INVOICE ID CUSTOMER ID PRODUCT ID HITS
321 1 444 1
322 2 411 1
323 3 221 1
324 4 321 1
325 5 444 2
326 5 444 2
As you can see, the row "hits" calculates how many times that particular customer has ordered that particular product.
Thanks for any help!

Assuming data in columns A, B and C try this formula in D2 copied down
=COUNTIFS(B:B,B2,C:C,C2)
That gives you exactly what you want - a count of rows where customer and product both match the current row

Related

Change array of SUMIF in case criteria exists in two different columns

A B C D E F
1 Results List A List B
2 Campaign Sales Campaign Sales Campaign Sales
3 Campaign_A 1.510 Campaign_A 500 Campaign_B 50
4 Campaign_B 120 Campaign_A 450 Campaign_B 40
5 Campaign_C 90 Campaign_A 560 Campaign_B 30
6 Campaign_D 1.650 Campaign_B 700 Campaign_C 80
7 Campaign_E 100 Campaign_B 710 Campaign_C 10
8 Campaing_F 70 Campaign_C 200 Campaign_F 70
9 Campaing_D 850
10 Campaing_D 800
11 Campaing_E 100
12 Campaing_F 320
13 Campaing_F 360
14 Campaing_F 290
15
16
The Excel table above consists of:
List A = Column C:D
List B = Column E:F
In each list campaigns can appear mutliple times.
In Column A:B I want to sum up the sales per campaign from the two lists using the SUMIF formula:
=SUMIF(C:C,A3,D:D)
=SUMIF(E:E,A3,F:F)
However, the List B should be prioritized over List A which means in case a campaign exists in List B (Column E) the SUMIF function should be only applied to List B and List A should be totally ignored.
The formula might look something like htis:
IF campaign exists in Column E then SUMIF(E:E,A3,F:F) else SUMIF(C:C,A3,D:D)
How can I achieve the desired results in Column B?
Or,
=IF(COUNTIF(E:E,A3)>0,SUMIF(E:E,A3,F:F),SUMIF(C:C,A3,D:D))
I would try with the following:
if(sumIf(E:E,A3,F:F)>0;sumIf(E:E,A3,F:F);sumIf(C:C,A3,D:D))

Cumulatively Reduce Values in Column by Results of Another Column

I am dealing with a dataset that shows duplicate stock per part and location. Orders from multiple customers are coming in and the stock was just added via a vlookup. I need help writing some sort of looping function in python that cumulatively decreases the stock quantity by the order quantity.
Currently data looks like this:
SKU Plant Order Stock
0 5455 989 2 90
1 5455 989 15 90
2 5455 990 10 80
3 5455 990 20 80
I want to accomplish this:
SKU Plant Order Stock
0 5455 989 2 88
1 5455 989 15 73
2 5455 990 10 70
3 5455 990 20 50
Try:
df.Stock -= df.groupby(['SKU','Plant'])['Order'].cumsum()

COUNTIFS with 2 different ranges and conditions

I have a table from which I need to count the ammount of specific numbers.
The table is dynamic and can have between 1 to 25 columns where the numbers are and then a code that starts with either a letter, 1 or 2. It has multiple rows too.
What I need is to have formulas to count the ammount of each specific number range if the code starts with the correct character as shown in the example image:
I can't manage to join the condition of the first range being between 2 numbers and the second range starting with a specific character.
The formula should look somewhat like this (count numbers between 200 and 299 with the code starting with 2):
=COUNTIFS(Table[[1]:[4]];">=200";Table[[1]:[4]];"<=299";Table[code];"2*")
letter 1 2 letter 1 2
100-199 200-299 200-299 2 1 1
300-399 400-499 400-499 3 3 3
500-599 600-699 2 2
700-799 2
1 2 3 4 code
139 307 165 B01
430 2CTE
581 703 PDC
312 354 528 746 GVM7
600 477 1OMC
299 425 413 2LP
231 666 420 433 1MLTQ
put this in F3 then copy over and down:
=IFERROR(SUMPRODUCT((Table[[1]:[4]]>=--LEFT(B3,3))*(Table[[1]:[4]]<=--RIGHT(B3,3))*(((ISNUMBER(F$2))*(LEFT(Table[[code]:[code]])=F$2&""))+((NOT(ISNUMBER(F$2)))*(NOT(ISNUMBER(LEFT(Table[[code]:[code]]))))))),"")
As per your comments to get everything between 400 and 499 and starts with 2:
=SUMPRODUCT((Table[[1]:[4]]>=400)*(Table[[1]:[4]]<=499)*(LEFT(Table[[code]:[code]])="2"))

EXCEL: Count of Column Items For Every Distinct Item In Another

In my Excel sheet, I have 2 columns. Names of restaurants, and ratings for each one. For each rating, a new row is created, so of course a restaurant name occurs multiple times.
Restaurant Rating
McDonalds 8
McDonalds 7
Red Robin 5
Qdoba 7
Etc.
How can I get the number of times each rating happens for each restaurant? We'll say rating goes from 1-10.
I want it to look like this:
Restaurant 1(rating) 2 3 4 5 6 7 8 9 10
McDonalds 889 22 45 77 484 443 283 333 44 339
Any help is appreciated!
Using Pivot Tables:
Use a pivot tables to set your rows at "Restaurant" and your columns as "Rating" and your values as "Count of Rating"
Using Countifs:

Excel find multiple values and copy them

I'm trying to make Up-Sells list for my personal web shop but cannot figure it out.
I have a lot of items in my database and I'm trying to sort them. I have unique ID's for categories and I need to paste every SKU which is under that category.
Input/Output
Input
SKU Category
123 1
124 1
234 2
235 2
Output SKU Category Up-Sell
123 1 123, 124
124 1 123, 124
234 2 234, 235
235 2 234, 235

Resources