fill in mulitple excel cells based on multiple cell values similar to a gantt chart - excel

I would like to create a Gantt chart like with excel based on task start and duration cell values. I have an excel as below:
Item
Start
Duration(months)
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
1
Q1
6
2
Q2
3
3
Q2
1
Start column indicates the quarter-calender the task starts.
Duration indicates the number of months the task can take to complete.
Based on these two value I would like to have a formula in columns Jan-Aug to fill with x appropriately
Desired output:
Item
Start
Duration(months)
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
1
Q1
6
x
x
x
x
x
x
2
Q2
3
x
x
x
3
Q2
1
x
I dabbled with XLOOKUP and OFFSET with no luck. Tried creating defined names as in Microsoft template with no luck

You can try the following formula in cell D2:
=LET(months, MONTH(D1:O1), dur, C2:C4, Qs, B2:B4,
QsUx, SORT(UNiQUE(Qs)), start, XLOOKUP(Qs, QsUx, SEQUENCE(ROWS(QsUx),,1,3)),
end, start + dur - 1,
GEN_X, LAMBDA(idx, MAP(start, end, LAMBDA(ss, ee,
LET(month, INDEX(months,,idx), IF(MEDIAN(ss, ee, month) = month, "x",""))))),
DROP(REDUCE("", months, LAMBDA(acc, m, HSTACK(acc, GEN_X(m)))),,1)
)
and here is the output:
Note: The formula generates the entire grid, there is no need to expand the formula.
Explanation
It uses the following two ideas:
To populate the grid using the MEDIAN function. Check the answer provided by #JosWoolley: Sum unique day count within a date ranges.
DROP/REDUCE/HSTACK pattern to iterate over all the month's columns to generate the x's for a given column. Check the answer provided by #DavidLeal to the question: how to transform a table in Excel from vertical to horizontal but with different lengths.
The rest is just to prepare/transform the input data in the format we want. The LET function is used for easy reading and composition.
The row with the months: D1:O1 was generated in date format as follows:
=EDATE(DATE(2022,1,1), SEQUENCE(1,12,0))
Now the months variable will have the corresponding months via the MONTH function, it returns the following sequence of values: 1,2,..,12.
QsUx has the unique names of quarters sorted. Then we can calculate the start date as follow:
XLOOKUP(Qs, QsUx, SEQUENCE(ROWS(QsUx),,1,3))
SEQUENCE generates the following sequence: 1,4,7,..etc. (as many values as rows have QsUx). Representing the starting month of each quarter.
Note: This is just one approach. The start can be obtained, by extracting the number of the Quarter and building a sequence: 1, prev. value + 3, for example. Alternatively, since we have only four quarters just a simple constant array with all the Qs and their corresponding start dates. The approach used in the main formula is more generic because the Gantt can be expanded to more than one year and it still works.
Having the start date, then we can calculate the corresponding end date as follows: start + dur - 1.
The user LAMBDA function GEN_X generates the x's values for a given column of months indicated by the idx as input argument (representing the corresponding month).
Finally, we use the DROP/REDUCE/HSTACK pattern to append each column to complete the grid.
Note: The solution assumes no excel version constraints as per the tag listed in the question, so all existing excel functions are available. If you have some limitations for example you don't have the DROP function, let me know to try to find some alternative.

Related

Excel - How to do the following?

I have a question related to EXCEL:
Since I have the following prices for different period, how can I compute in an automatic way, for example the price between 10 June - 15 July ?
EDIT--> Expected output:
50€+50€ (10-11 june) + 58€x13 (period 12 june - 25 June) + 75€x13 (period 26 june - 9 July) + 92€x5 (period 10 july-15july) = 2289€
This is the same pictures with the cells in excel, please do not consider the "Price of period", but only the daily price
You could do this with a (lengthy) calculation:
Consider:
A8 Contains the from date (10-06-2021)
B8 Contains the from date (17-07-2021)
=(MIN($B$8,D3)-MAX($A$8,C3)+1)*C5+(MIN($B$8,F3)-MAX($A$8,E3)+1)*E5+(MIN($B$8,H3)-MAX($A$8,G3)+1)*G5+(MIN($B$8,J3)-MAX($A$8,I3)+1)*I5
This will consider a period from 10-06 - 11-06 a period of 2 days. And also 12-06 - 25-06 a period of 14 days, and so on.
The result is: 2514.00
One method would be to create a lookup table and use a formula.
Given your data, your lookup table might as shown below:
I NAME'd it: priceTable
You can then use the formula:
=SUM(VLOOKUP(SEQUENCE(End-Start+1,,Start,1),priceTable,2))
If, for some reason, you cannot easily create priceTable, you can create it with a formula (depending on your version of Excel):
=INDEX($C$4:$I$6,{1,3},{1;3;5;7})
Note: All of the formulas assume your dates are real dates and not strings.
If your version of Excel does not have the SEQUENCE function, you can replace it with:
=SUM(VLOOKUP(ROW(INDEX($A:$A,Start):INDEX($A:$A,End)),priceTable,2))

Is there a non-VBA way to calculate the average of the sum of two sets of columns?

I'm creating an excel spreadsheet to track when an item is received as well as when a response to the item having been received has been made (ie: my mail was delivered at 1:00pm (item received) but I didn't check the mail until 5:00pm (response to item having been received)).
I need to track both the date and time of the item being received and want to separate these in two separate columns. At the moment this translates to:
Column A: Date item received
Column B: Time item received
Column L: Date item was responded to having been received
Column M: Time item was responded to having been received
In essence I'm looking to run calculations on the response time between when the item is received and when it has been responded to (ie: average response time, number of responses in less than an hour, and even things like the number of responses that took between 2 and 3 hours where Bob was the person who responded).
The per-line pseudo code would look something like:
(Lr + Mr) - (Ar + Br) ' where L,M,A,B are the columns and 'r' is the row number.
An example, with the following data:
1. A B L M
2. 1/5/19 10:00 1/5/19 12:00
3. 1/5/19 21:00 1/6/19 1:00
4. 1/5/19 22:00 1/5/19 23:00
5. 1/6/19 3:00 1/6/19 4:00
The outcome for the average response time would be 2 hours (average(rows 2-5) = average(2, 4, 1, 1) = 2)
The number of items with an average response times would be as follows:
(<=1 hour) = 2
(>1 & <=2) = 2
(>2 & <=3) = 0
(>3) = 1
I don't know (or can find) a function that will perform this and then let me use it within something like a countifs() or averageifs() function.
While I could do this (fairly easily) in VBA, the practical implementation of this spreadsheet limits me to standard Excel. I suspect that sumproduct() will be fundamental to make this work, but I feel that I need something like a sumsum() function (which doesn't exist) and I'm not familiar with sumproduct() to better understand what to even look for to set something like this up.
If you are not so familiar with SUMPRODUCT() or the likes I would suggest one helper column. Like so:
You can see the formula used is:
=((C2+D2)-(A2+B2))
You can probably do all type of calculations on this helper column. Note, column is formatted hh:mm. However, if you want to look into SUMPRODUCT() you could think about these:
Formula in H2:
=SUMPRODUCT(--(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<=1))
Formula in H3:
=SUMPRODUCT((ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>1)*(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<=2))
Formula in H4:
=SUMPRODUCT((ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>2)*(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<3))
Formula in H5:
=SUMPRODUCT(--(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>3))
The helper column is the easiest approach. It gives you the time differences that you can then easily analyse however you want. Analysis without the helper column is possible, but the approach differs depending on what type of analysis you want to do.
For the example you provided, which is counting the number of time differences grouped into ranges, you would use the FREQUENCY function:
=FREQUENCY(C2:C5+D2:D5-A2:A5-B2:B5,F2:F4)
In F2:F4 (called the "bins"), enter the upper limit of each range you want to count. The Frequency function counts up to and including the first value, then counts from there up to and including the second value, and so on. Enter the bins as times, e.g. 1:00 for 1 hour.
Note that Frequency is an array-entered and an array-returning function. This you means you need to first select the range that will contain all output values, G2:G5 in this example, then enter the function, then press CTRL+SHIFT+ENTER
Also note that Frequency returns an array that is one element larger than the number of bins specified. The extra element is the count of all values greater than the largest bin specified.

Combining formula using and / or in excel

Case 1
I have a set of data which i need to determine if the cell is in Business Hours or Not.
8 - 18 (08:00 - 18:00) Business Hours (BH)
outside the timeframe is Non Business Hours (NBH)
Given Cell value for example is = "7" (which is NBH)
here is the formula i created =if(AND(C2>=8,C2<=18 ),"BH","NBH")
Case 2
I have a set of data for days in a week, i need to determine if the cell is in Weekdays or Weekends.
I have this formula = =if(OR(I2="Saturday", I2="Sunday"), "NBH", "BH")
note : i used the same variable name NBH - Weekends , BH - Weekdays
What I really need to do is to combine those two cases into 1 formula.
I need to output these scenarios correctly, listing below :
Time is 08:00, date is Saturday/Sunday = Combined formula of case 1 and 2 should output "NBH"
Time is 07:00, date is Monday-Friday = Combined formula of case 1 and 2 should output "NBH"
Time is 12:00, date is Monday-Friday = Combined formula of case 1 and 2 should output "BH"
Formulas can be seen in column BH/NBH WEEKDAYS and BH/NBH Weekends, you can browse attached file thanks much!
Click to access the file
If you want to calculate it directly on the initital values:
=IF(OR(H2="Saturday", H2="Sunday", B2>18, B2<8), "NBH", "BH")
p.s. Alternatively you can combine the already calculated columns, if you intend to keep these columns:
=IF(AND((E2="BH"), (D2="BH")), "BH", "NBH")

DAX Calculation with Datesbetween Ignores all Datefilters

I am starting with DAX.
I have a standard date table and a table with sales. When I try to show the running total with the below formula the month filter is ignored, as shown:
The formula is:
Prov YTD VJ 2:=CALCULATE(FIRMPROV[SumProv];
All(Kalender[Jahr]);
DATESBETWEEN(Kalender[Datum];
Min(START_YTD[start_ytd]);
MIN(END_YTD[end_ytd])))
A good way to calculate running totals is by using the FILTER and EARLIER functions, but a prerequisite to that is that you need to create a Month Number column (ie. Jan = 1, Feb = 2, Mar = 3, etc.)
Then, you can use the following DAX:
CALCULATE(SUM([SumProv]),ALL(FirmProv),FILTER(FirmProv,[Month Number]<=EARLIER([Month Number])))
EARLIER basically is DAX's way of interpreting the current row. You're telling DAX to sum ALL of the rows in the FirmProv table where the month number is less than or equal to the current row (AKA running total).
Here's the result (note the numbers aren't exactly like yours, I just quickly mocked it up to show the example):

Data Chart to show times of day in Excel

I have a data set where by i am required to show the sum of calls for a date and their call times also.
Here is an example of my data set for a few days for one extension
6/24/11 7:43:38 AM
6/24/11 8:10:23 AM
6/24/11 8:16:54 AM
6/24/11 8:20:45 AM
6/24/11 4:47:06 PM
6/25/11 12:38:43 PM
6/25/11 5:38:10 PM
6/26/11 7:32:53 AM
6/27/11 5:40:32 PM
6/28/11 3:46:05 PM
6/29/11 7:09:21 PM
6/30/11 5:59:54 AM
6/30/11 1:21:28 PM
6/30/11 5:59:00 PM
Is it possible to put this into a chart whereby we can see a sum of calls for a given date? If that makes sense.
Thanks,c
-=
I found the following post at Excel Timesheet
this fixed my problem.
Easiest way is to have a number of helper columns:
Example:
Column A through C contain the raw data for Extension 1-3
Column D through E contain the 'truncated' version of the time stamp into days
Column H through K would contain the frequency of calls for a given day and extension
Put the formula in E in order to get the truncated day, and expand it over the columns E-G
=DATE(YEAR(A3),MONTH(A3),DAY(A3))
Put the starting day of interest in Cell I2. For Cell I3 enter the formula
=I3+1
so you will have automatically incrementing days in that column, this is your 'bin' for the histogram you're about to make.
Count the number of times the value in E is found for a day in your bin
In J ( column counting calls per day for extension 1 ) enter the formula:
=COUNTIF(E$3:E$16,$I3)
drag this formula out.
Now you should have the data for your histogram/plot in columns I through L.
I found the following post at Excel Timesheet
this fixed my problem.
Excel Timesheet

Resources