How to count appearences along a timeline with criteria - excel

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)

Related

How can I predict the Monthly Recurring Revenue (MRR) for a product when I have transactions for only 4 days?

I assume I want to extrapolate to find the sum of the MRR at month's end (for January), however, I only have transactions (each has it's own MRR value of course) for January 3rd,4th,5th, and 6th.
I tried to use =forecast but I keep getting a large negative number which does not seem right at all. If A2:A5 contain the values of 8234.72, 2374.9, 2231.054, and 5386.3505 and then B2 is 1/3 or perhaps just 3 is better and it goes all the way down to 31 for the amount of days in January, I am unsure of how to predict the total MMR at the end of the month, I keep getting errors.

Counting total duration of stay with multiple entries per customer

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))

Assign specific dates based to an employee level dataset on weighted averages in excel

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.

Formula that provides multiple answers based on different outcomes in different cells

I have been banging my head against a brick wall trying to work out a formula, any help would be amazing!
SO....
I have three columns that work out annual leave.
COLUMN 1 = AMOUNT OF HOLIDAY A PERSON HAS REMAINING FOR THE YEAR
COLUMN 2 = AMOUNT OF HOLIDAY TAKEN IN REPORTING MONTH
COLUMN 3 = NEEDS A FORMULA TO WORK OUT IF THE PERSON HAS GONE OVER THEIR ANNUAL LIMIT, OR WHETHER SOME OF IT HAS, OR WHETHER THEY ARE ENTITLED TO THE FULL MONTHS ALLOCATION
Ie: If a person has taken 5 days holiday in COLUMN B, but in COLUMN A it is saying they have gone over their annual allowance by 2 days, the cell in COLUMN C needs to return zero (they dont get paid for holiday taken in Column 2 as they have already gone over their annual amount shown in COLUMN A)
If a person has taken 5 days in COLUMN B, but in COLUMN A they have 10 days remaining, COLUMN C should return 5 as they had 10 days remaining for the year, and taken 5 days in COLUMN B, so they are fine to be paid the 5 days they took
If a person has taken 5 days in COLUMN B, but in COLUMN A they only have 2 (2 days remaining for the year), in COLUMN C it needs to return 2 (as they are only allowed to be paid for 2 of the 5 days that took)
I have no idea how to do this...and its driving me mad! PLEASE HELP!!
How about this
=IF(A2<=0,0,IF(A2-B2>=0,B2,A2))
if you have overdrawn in column A it gives 0
if you have taken some, but not reaching over your limit, it gives number of days you have taken
otherwise (you have days remaining, but not enough to cover everything) it takes the remaining number of days
edit: changed the formula to show , instead of ; as people apparently mostly use a different regional setting than me.

Excel - What is the best way to analyse the following data?

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.

Resources