How to count the amount of times a field appears in a specific 'week' in excel - excel

I have a table:
I've created a new column called Distinct Delivery Week, where I have the weeks 1-52 listed.
I want to create a count function if Week == distinct delivery week, make it so it does a count and returns the Channel category that has the most appearances in each respective week.
For example, if App - Activation Organic appears more often than anything else in Week 1, then it will be returned in a new column next to Distinct Delivery Week

With so many data, it may be helpful if you use a simple PivotTable to count how many times per week does each channel appears, and get TOP 1 per week.
I made a fake dataset kind of like yours:
Then I created a Pivot Table like this:
Fields WEEK and CHANNEL into rows section (first WEEK, second CHANNEL, the order is important)
Again, field CHANNEL into VALUES section (make sure the field does a COUNT operation)
Applied a VALUE FILTER in column CHANNEL --> TOP 10, set it up to show just TOP 1
It's a really easy way to get a list where you can see the channel that appears most per week.

I figured out how to do it using this source.
The formula I used was:
{=INDEX(D1:D74686, MODE(IF(H2:H74686=M2,MATCH(D2:D74686,D2:D74686,0))))}

Related

Excel: Count distinct numerical values if string condition matches

I have a list of employee names on one tab and another tab with orders shipped by employees and the month they were shipped going back 12 months. I'd like to calculate the average number of products shipped per employee per month, but I need to know how many months they were here to do that. So what I'd like to do is essentially write a formula that says give me the count of the distinct number of months they've been shipping products.
Sample employee data:
And here's the sample data on the individual shipments:
So in short, I need to know that Joe Smith shipped those 250 products across 3 distinct months to see he averages 83.3 shipments per month. Again, because there are many new people who have come onboard in the last 12 months, I can't just divide them all by 12 and need to know how many months they were shipping items in.
FILTER Shipper and Month based on Shipper column with criteria Employee name. Apply UNIQUE on filtered array to get only unique values (name + month number). Use COUNT to get active months. Divide Products Shipped by it.
Result:
Average by Count of Uniques
=LET(Shippers,B2:B11,Months,C2:C11,uShippers,E2:E4,uProducts,F2:F4,
uMonths,BYROW(uShippers,LAMBDA(uShipper,
ROWS(UNIQUE(FILTER(Months,Shippers=uShipper))))),
IFERROR(uProducts/uMonths,""))
You can use this array version, which spills all the results at once:
=LET(empl, A2:A4, prods, B2:B4, shipper, B7:B16, months, C7:C16,
ux, MAP(empl, LAMBDA(e, COUNT(UNIQUE(FILTER(months, shipper=e))))), prods/ux)
Here is the output:
It is also possible not using MAP but it is a verbose solution:
=LET(empl, A2:A4, prods, B2:B4, shipper, B7:B16, months, C7:C16,
left, TRANSPOSE(N(shipper=TOROW(empl))), right, N(months=TOROW(UNIQUE(months))),
cnts, N(MMULT(left, right)>0), ux, MMULT(cnts, SEQUENCE(ROWS(cnts),,1,0)), prods/ux)
Replacing TOROW with TRANSPOSE it should work for older Excel versions.
This is how I would have done it, create a Pivot table(Insert->Pivot Table) with Months as column, Employee as row and the values as count of shipments. Once you have the Pivot table, your life becomes easier. Now you do a count of the employee row (COUNT(COL-1:COL-X)) to count the total months a particular employee showed up.You now have count of shipments and a count of months. You can calculate the average. Not sure I can think of anything else easier.

excel PowerPivot Auto Calculated Measures & Columns

After looking at a few similarish questions I figured I needed something more specific so asking here. I will start by explaining the situation:
The Setup
I have a Store which sells Cakes, Cookies and Wine. I have the weekly sales data of each product sorta like this:
Product ID
Product Name
Quantity
Value
Week Ending
1
Ginderbread
2
£4
13/01/22
2
Chocolate chip
5
£25
13/01/22
3
Red Wine Bottle
1
£10
13/01/22
4
Sponge Cake
3
£9
13/01/22
Currently every week's data is stored within the same table, with me using a Week filter to show only the week i'm interested in.
Using this Data I created PivotTables that shows the sales of each category, with the ability to drill down to show the specific products. Table looks something like this:
Category
Quantity
Value
Cakes
2
£4
Cookies
7
£29
Wine
1
£10
The issue
I now want to stick in a new calculated column that shows the Value as a %. E.g The total value for the previous table was £43, so Cookies is about 67%. If I drill down, it would show the Chocolate Chip record as 80% and Gingerbread as 20%
I imagine doing this would be easier if each individual week's data was on a different table, but I got a lot of weeks and I also want to do tables showing the sales for over a period of time. Plus I don't know of a way to merge the "value" and "quantity" columns, etc instead of having 1 for each week being shown.
any advice would be appreciated
Create an extra column in the source table (prior to filtering) entitled "perc" calculated as the corresponding value for each row divdied by the total value across all rows (se pic. / eqn. for first row below) --
=E2/$E$6
No calculated fields required - just include perc as the mesaure of interest in your pivot table, with value setting as 'sum':
The reason why this worked is because of the common denominator - which allows one to sum ratios on a 1:1 basis.
Devising a calculated field using the standard 'fields, items & sets' functionality for ordinary pivot tables would not be feasible / possible as far as I am aware. You would need to move into the realm of power pivots and data models - which is not too complicated (readily accesible directly from the field list per below) - however, I see this as unnecessary complication for the task at hand.
Side notes:
Using table names in your functions is sometimes more convenient when entering, albeit may appear tricky at first when reviewing - first eqn above becomes:
=[#Value]/Table1[[#Totals],[Value]]

Subtracting minimum and maximum data from the group in Excel

I have a problem with extracting the data from dataset. In my company project has some processes, which are grouped in categories. So I have one project which has many processes grouped. On the basis of column "D" I would like to get the first data and the last date from every kind of category. For example, for project 20.28 I would like to have start date from row 5 and finish date from row 4. I hundreds of projects divided into categories so making it manually isn't and option here. Below is a sample.
Sample data set
I have a solution based on consecutive filters with formulas. If this works to you I'll post here the steps.
https://drive.google.com/file/d/1pdxMGRDl_sV5wRmqIFouDQs8L43LVxgi/view?usp=sharing

Pivot Table project - Avoid using many INDEX and MATCH functions that make Excel crash

I need some help with an Excel Project that's giving me headaches. I succeeded to achieve everything I wanted but the result is too heavy for Excel and it crashes all the time. I'm over-using the INDEX and MATCH functions on large tables (50 000+ lines) and Excel doesn't like it. I'm looking for a way to do the same thing in a lighter way for Excel.
Here's what I achieved : I created a report that helps me analyzing my employees's performance VS their billing targets. To create such a report, I used a Pivot Table.
That Pivot Table needs this information as its source :
Each sales that every employee made (amount in $ and date)
The hourly rate of each employee (which changes for every period, see TABLE1 below)
The billing target for each employees (which changes for every period, see TABLE1 below)
Here's my setup. I have 3 tables :
TABLE1 (See attached image) - A table where I manually input data for each of my employees (hourly rate and billing target). Their billing target and hourly rate change every period. So, each period has a different line and I indicate the first day of the period and the last day of the period.
TABLE2 (See attached image) - Table that contains sales data exported from another software I use. Each line represents an amount sold by an employee to a customer on a specific date. This table is pretty heavy and contains more than 50 000 lines. Moreover, the last 2 columns of this table use Index and Match functions to get the right hourly rate and the right billing target from TABLE1. That means that each of those 50 000 lines uses the INDEX and MATCH functions twice… This part is too heavy for Excel and I need a workaround.
Moreover, TABLE2 is getting refreshed every few days with new data coming from my other software (an ERP). So the solution I need to find must take that into account and must be permanent (I try to avoid steps that will have to be done everytime I refresh TABLE2 with new data).
TABLE3 - A Pivot Table that uses TABLE2 as its data source. I use the slicer to select the name of an employee and a timeline to specify which months I want to display. Then the Pivot Table shows my employee's statistics grouped by months. The main statistic is the amount of "billed hours" for each employee, which is in reality the amount of sales made by that employee, divided by their hourly rate on a specific date.
My thoughts :
It is absurd that TABLE2 uses that many INDEX and MATCH functions. For example, if Employee1 made 500 sales between 2020-07-01 and 2020-07-31 (the same month, thus the same period, thus the same hourly rate and billing target), there will be 500 different lines that will use INDEX and MATCH to get the same hourly rate and billing target from TABLE1. That leads to a lot of duplicated calculation and a lot of duplicated data.
Would it be possible for a Pivot Table Calculated Field to use INDEX and MATCH in its formula? And would it be lighter for Excel to do so?
Another way would be to add, at the bottom of TABLE2, 12 lines per year (1 for each month) for every employee where I would write their hourly rate and the billing target. That way, the Pivot Table would be able to display an hourly rate and a billing target for each month, for each employee. That solution would work and would be lighter for Excel, but it would create a high risk of making mistakes while manually inputting the data.
I'm open to all suggestions including VBA!
Thank you very much for your precious time!
EDIT : FORMULA
As requested, here's my INDEX AND MATCH formula that is in TABLE2 and gets the hourly rate from TABLE1 :
=INDEX(TAB_Employee_Data[[#All];[Hourly_Rate]];MATCH([#[Date (Cell)]]; IF(TAB_Employee_Data[[#All];[Name]]=[#[Employee(Cell)]];TAB_Employee_Data[[#All];[First day of the period]]);1))
TAB_Employee_Data is the tab that contains "TABLE1".
I translated the names of the fields since all my work is in French.
This formula does the following : it searches the name of an employee in TABLE1 and finds the period which fits the date of a line in TABLE2.
Also, to work properly, I need to sort the lines of TABLE1 in chronological order.
TABLE 1 :
TABLE 2:

Top 3 Values for Multiple Categories based on hours in a week

I'm working on a charging matrix where project managers can input time to the top three contracts in each category based on a week to week basis. Right now I have a pivot table with the categories (Production, Spares, Development) with multiple contracts that were charged that week. I manually select the top three from each category and copy into a table where I have formulas creating charge numbers for the project managers to use.
The question is, is there a way I can automate selecting the top 3 contracts from each category based on number of hours for that specific week?
Pivot Table & Charging Matrix
You can use LARGE() to get the top 3 (large(data,1) etc)
Then use index() and match() to get the contract names.
I have made a simple example here, but it will not deal with duplicate results in the hours if they are in the top 3...
There are solutions to that already posted.
If I understand you correctly, you want to automate the process of finding the top 3 contracts under each category and then create the charge number based on the results.
You can do so by creating a new pivot table as demonstrated below, put the Category Name and Contract Name in the Rows field, and put the Hours in the Values field, then right click anywhere within the Row Labels column of the pivot table, go to Filter -> Top 10... -> enter 3 in the second field, then you should have the top three contracts for each category.
P.s. You can choose to sort the hours from largest to smallest, and choose NOT to show the subtotals for each category.
Once you have the list, you can enter your formula (I presume you used a formula) in corresponding cells in column H (as in my example) to create the desired charge number.

Resources