I have an excel file that has 2 spreadsheets. First spreadsheet ("masterlist") contains the masterlist with 4 columns:
CustomerID
Checkin
Checkout
Duration
1
9/1/2020
9/3/2020
A customer might have multiple entries as they could've checked in and out multiple times. There's thousands of records/rows overall.
The 2nd spreadsheet ("Infosheet") just has ONLY the unique customers from masterlist and is structured:
CustomerID
Total_Duration
1
My end goal is to calculate the total duration of each customer's stay.
For calculating Duration in "masterlist," I did a simple if statement formula:
=IF(checkout=checkin,1,checkout-checkin+1)
If statement, because if the checkin and checkout are on same day, the customer is still considered to have stayed 1 calendar day. The addition of 1 in the false case is done to account for the same full calendar day. So a stay of 9/1-9/3 should yield 3 days total.
Long story short, I ended up with a formula that reads the following for the "Infosheet"'s Total_Duration:
=SUMIF(masterlist!$A:$A,A2,masterlist!$D:$D)
Problem is that there's multiple assumptions made using my logic that ends up getting multiple records wrong.
If a customer has the following two records:
Checkin
Checkout
Duration
9/1/2020
9/3/2020
3
9/3/2020
9/5/2020
3
My formulas calculate the duration of stays for both as 3 days and in the "Infosheet" the total duration would show as 6 days. The correct result would have been 5 days, because we shouldn't be counting 9/3/2020 twice.
My formula also doesn't account for a case like the one below:
Checkin
Checkout
Duration
9/1/2020
9/3/2020
3
9/3/2020
9/3/2020
1
10/1/2020
10/3/2020
3
10/3/2020
10/3/2020
1
While the duration, in isolation, are calculated correctly, the SUMIF would give us a total duration of 8 days. In reality, the 9/3-9/3 and 10/3-10/3 stays have already been accounted for in the 9/1-9/3 and 10/1-10/3 stays so it shouldn't have been counted again and the total duration should've been 6 days.
I am completely stumped on what should be my next step. How do I account for these examples in my formula? How should I be manipulating the data/changing or adding columns to make this easier?
Thanks in advance!
we can use Sequence to create an array of days from the Min to the Max dates and use COUNTIFS to find if they fall inside the ranges.
=LET(
ID,A:A,
ckin,B:B,
ckot,C:C,
ids,F2,
mn,MINIFS(ckin,ID,ids),
mx,MAXIFS(ckot,ID,ids),
sq,SEQUENCE(mx-mn+1,,mn),
SUMPRODUCT(--(COUNTIFS(ckin,"<="&sq,ckot,">="&sq,ID,ids)>0))
Related
I have the above sales order data which lists a day by day update of orders as they go through each stage until shipped. Orders 1 and 2 are shown alongside the status of that order for each date between 1st and 08th February.
What I need to do (in a pivot eventually), is to count the number of days for each order that they were in each state. So for example Sales number 1 was in a processing state for 4 days and a packed state for 3 days and then finally a shipped state for 1 day. I want these 3 numbers displayed beside each status maybe on a separate line?
For example
Sales Number 1
Processing - 4 Days
Packed - 3 Days
Shipped - 1 Day
You'll also notice that on Sales Number 2, the order went back into a "On Hold" state, this can occur in my dataset so just count it as normal e.g On Hold - 2 days.
How would I get this count using a formula or pivot etc?
Simplest way is to use pivot table:
I have a table with 3 columns: expense, client_id, date.
The date has record of clients expense for half a year for each day.
Some clients spend many each day, but some not.
The expendure ranging from zero to few hundreds.
I want to group/count active client, which spend over 50 dollars each day, and calculate how much clients was active between 0-30 days, 30-60 days, 60-90 days, 90-120 days, 120-150 days, 150+.
I mean if client spend at least 50 dollars each day along 40 days, i add him to 30-60 days column.
client id appears only once each day.
expense
client_id
date
20
1
01/01/2000
60
2
01/01/2020
70
3
01/02/2020
the result should be like that
0-30 days
30-60 days
60-90 days
90-120 days
9
3
12
20
the values are count of active clients
Thank you a lot
There might be better solutions with less helper columns, but this is what I can offer at the moment.
Preparation
I generated some random data in columns A to C for 10 clients, one month and an expense limit of 100. You will have to adjust the expense threshold and the day ranges to your needs.
Helper columns and formulas
criteria_met checks whether the expense is higher or equal the given threshold (here 10). Formula in D2 is =IF(A2>=10,TRUE,FALSE).
is_consecutive checks whether the client had an entry on the previous day. Formula in E2 is =IF(COUNTIFS(B$1:B1,B2,C$1:C1,C2-1)>0,TRUE,FALSE).
consecutive_group assigns a number for each group of consecutive days, on which the client had an expenditure above or equal the threshold. Formula in F2 is =IF(AND(D2=TRUE,E2=TRUE),MAXIFS(F$1:F1,B$1:B1,B2),MAXIFS(F$1:F1,B$1:B1,B2)+1). Whenever the combination of criteria_met and is_consecutive is FALSE, the group number is increased by one.
days_per_group counts the number of days per client_id and consecutive_group. Formula in G2 is =COUNTIFS(B$1:B2,B2,F$1:F2,F2).
max_per_group makes sure that only the max number of consecutive days is considered per consecutive group. Formula in H2 is =IF(G2=MAXIFS(G:G,B:B,B2,F:F,F2),G2,0).
Result table
labels creates the headline. Formula in J3 is =J2&"-"&K2-1&" days"
values counts how often a number between the given thresholds occured. Formula in J4 is =COUNTIFS($H:$H,">="&I$2,$H:$H,"<"&J$2).
Requirements
Each client can only have one entry per day
The source list (A:C) has to be sorted by date
Please let me know, if you need more information.
how to count values in K4 ?
=COUNTIFS($H:$H,">="&J$2,$H:$H,"<"&K$2)
I have a dataset in excel which shows headcount by employee level and which department each employee would fall under (sales, ops, or support). I would like to send a survey to each employee once every 26 weeks (2 times a year), but I would also like to keep sending surveys every week to ensure continuation of surveys to a certain amount of population split between sales, ops, and support departments based on their weight of the total population.
This way, I am sending surveys every week to a tiny bit of my overall headcount but only repeating people every 26 weeks.
Can anyone please help on how to solve this in excel with a formula?
From attached sample data, how can I split the headcount to send surverys for 26 weeks straight but to different population every week and not repeat? This different population should be split by % of department out of total headcount. Meaning if I have 10 people every week and % split is 40% sales, 30% operations, and 20% support, the survey should be sent to 4 sales, 3 operations, and 2 support people. Please note that the 10 people and the %s may vary every week because of new hires and resignations.
Thank you!
Sample Data
In the data sheet, ceate a helper column D, where you hand out the numbers to each employee, label it MOD. Use the formula for each employee, enter to cell D2:
=MOD(ROWS(A$2:A2)-1;$H$2)+1
That way each employee is assign a number from 1 to whatever is in the cell H2, e.g. 26. Then contact list all employees with 1 and you have the first batch and so you continue each week to get to employees with 26 in 26 weeks. This way all get the survey but just once.
Of course the share of the individual depts cannot be achieved each time, as there are less employees in some. If you wanted to keeps the shares, some employees of the smaller departments would get the survey more times.
If you want to get some randomness into the order, just mix the order of MOD numbers, e.g. start with 7, continue with 23 etc.
I hope I got the question right, I am not sure in some parts.
I am working on an excel sheet where I am required to calculate average number of days the stores in a city were able to make some sales. I am attaching a sample of the table for reference. The values in the cells represent the number of units sold(not relevant to this question).
Here across NY, two stores are present, and out of the total number of days in consideration (3*2), only 4 days some sales were made, making the average 66%.
Similarly for Paris, there exists only one store which was open across all days.
To arrive at the figures, I tried using nested countifs and SUMIFS , but did not receive the expected results. Also, in some of the older posts, users had suggested to use INDEX MATCH with SUMIFS, but I was not to get accurate results using these.
Can anyone help me to get the correct figures for Total days, and Days with some sale.
SUMPRODUCT SOLUTION
=SUMPRODUCT(--(A$2:A$5=A8)*--(C$2:E$5<>""))
=SUMPRODUCT(--(A$2:A$5=A8)*--(C$2:E$5<>"NO SALE"))
=ROUND(C8/B8,4)
First, according to your grid NY made sales on 4 of the 6 days. (NY1: Mon, Wed; NY2: Tues, Wed). Thus the average is not 50% but 66%.
Second, to get your formula. Assuming "Place" is in column A. Below is for NY, you can solve for the rest.
Total number of days:
In cell "C9": =COUNTIF(A2:A4,"=NY") * 3
Days with sales:
In cell "D9": =COUNTIF(C2:E2,"<>NO SALE") + COUNTIF(C4:E4,"<>NO SALE")
I'm looking for the best way to analyse the following data.
This is the amount in hours an employee has taken in a year and what remains. The data bars are a percent of hours taken from what they're allotted, shown in column K. Col I is how many hours they have left, and col J shows the cumulative holiday they've taken throughout the year.
I need the relevant info shown on one row where each row will be an employee's holiday history. Different employees have different hours and I need a way that shows who is in most need of taking holiday when that filtering from largest to smallest etc.
Where I find this tricky is if an employee had 10 hours allotted, and has taken 2 hours, that's 20%, which is the same if someone had 100 hours and has only taken 20 hours. But it's clearly more important that the second employee uses up some of their leave. I'm struggling with the best way to represent this.