Count day of week between dates from another column in excel - excel

Consider the following sheet:
A B C D E
---------------------------------------
| Non
| Start End Mon Mon
1| Date Date Vac Vac Vacation
| Days Days Days
2| 11/16/17 11/30/17 1 2 11/21/2017
3| 12/1/17 12/15/17 0 0 11/22/2017
4| 12/16/17 12/31/17 0 4 11/27/2017
5| 12/26/2017
6| 12/27/2017
7| 12/28/2017
8| 12/29/2017
What formula can I put in cells C2:D4 to get the values needed?
Notes:
The formula should only lists those vacation days in column E:E that are in the range of A2&B2 (if solving for C2 and D2)
In this example only vacation date 11/27/2017 is a Monday.

Might the following work in C2?
=SUMPRODUCT(--(WEEKDAY($E$2:$E$8,2)=1),--($E$2:$E$8>=A2),--(‌​$E$2:$E$8<=B2))
Here it is deployed in sheet with UK date format:

Related

Can you autofill WorksheetFunction formula?

I would like to know if it is possible to apply the WorksheetFunction on a range instantly.
For example, say I want to Vlookup with the Index 1 & 3 to get their ID Num
|Index|Name|Sales|ID Num|
|-|-|-|-|-|
|1| A| 2| 123|
|2| B| 3| 321|
|3| A| 5| 456|
|4| A| 1| 654|
I managed to achive it on the vlookup function:
Range("J2:J3")=WorksheetFunction.VLookup(Range("I2:I3"), Range("A:D"), 4, 0)
Where :
"I2:I3" are the cells storing the criteria 1 & 3
"A:D" is the column Index, Name, Sales & ID Num
The excel formula version is "=VLOOKUP(I2,A:D,4,0)"
It returned me :
cell "J2" = 123
cell "J3" = 456
,which is good but when I use the same methodology on the SUMIF function, it gives me a run-time error Type mismatch
Here is the code : Range("G2:G3") = Application.WorksheetFunction.SumIf(Range("B:B"), Range("F2:F3"), Range("C:C"))
Where :
"B:B" is the column Name
"F2:F3" are the cells storing A & B
"C:C" is the column Sales
The excel formula version is "=SUMIF(B:B;F2;C:C)"
In the formula above, I want to get the total sales for A & B
Have I done something wrong?Or is there an alternative?
Please let me know
Thanks in advance

number of zero days in a row field

I have a spark dataframe like the input column below. It has a date column "dates" and a int column "qty". I would like to create a new column "daysout" that has the difference in days between the current date value and the first consecutive date where qty=0. I've provided example input and output below. Any tips are greatly appreciated.
input df:
dates qty
2020-04-01 1
2020-04-02 0
2020-04-03 0
2020-04-04 3
2020-04-05 0
2020-04-06 7
output:
dates qty daysout
2020-04-01 1 0
2020-04-02 0 0
2020-04-03 0 1
2020-04-04 3 2
2020-04-05 0 0
2020-04-06 7 1
Here is a possible approach which compares if current row is 0 and lagged row is not 0 , then takes a sum of that window , which then acts as a window for a row number to be assigned and subtract 1 to get your desired result:
import pyspark.sql.functions as F
w = Window().partitionBy().orderBy(F.col("dates"))
w1 = F.sum(F.when((F.col("qty")==0)&(F.lag("qty").over(w)!=0),1).otherwise(0)).over(w)
w2 = Window.partitionBy(w1).orderBy('dates')
df.withColumn("daysout",F.row_number().over(w2) - 1).show()
+----------+---+-------+
| dates|qty|daysout|
+----------+---+-------+
|2020-04-01| 1| 0|
|2020-04-02| 0| 0|
|2020-04-03| 0| 1|
|2020-04-04| 3| 2|
|2020-04-05| 0| 0|
|2020-04-06| 7| 1|
+----------+---+-------+

Excel formula to get table value on nth row

| ID | Email | Username
1| 1 test#email.com Test
2| 2 123#test.com ABC
3| 3 bca#123.com 123
The table above is titled Table3
I need to get the value for the specific column (which is specified in cell A1 on the nth line).
So for example here is a work sheet
| A |
----------------
1| Email
2| =Index(Table3[A1], 1, 0)
3|
This should return test#email.com
However, Table3[A1] is looking for a column titled A1 rather than Email
Please try:
=INDEX(INDIRECT("Table3["&A1&"]"), 1, 0)

EXCEL: Return a row value based on the row with highest max value

I've seen some similar questions for this, however none were suited correctly.
I'm wondering if I can return a row cell based on the max value in the same row, but different cell.
So I have this;
| A | B | Date
1| X | 2 | 01/01/17
2| Y | 3 | 17/01/17
3| Z | 4 | 18/01/17
4| X | 2 | 21/01/17
5| Y | 3 | 03/02/17
6| Z | 4 | 03/02/17
7| Z | 4 | 07/03/17
8| Z | 4 | 09/03/17
9| Y | 3 | 13/03/17
So Column A displays a string, and Column B counts how many times that Column A string is repeated. I have another sheet with a row for each month, being 01, 02, 03, 04, etc. I am trying to get the string from Column A, which the highest value in Column B, grouped by each month. So for the above example, the next sheet would look as so;
| A | B
1| X | 2
2| Draw | 1
3| Z | 2
I have been able to achieve the date grouping aspect for similar functions using;
IFS(E:E,D:D,">=" & DATE(A$2,B6,1),D:D,"<=" & DATE(A$2,B6,EOMONTH(B6,0)))
If anyone has any ideas on how I could achieve this, it would be much appreciated!
Edit;
I've managed to figure parts of it out, I have been able to get the most common name (without checking for multiples) using
=OFFSET(A1,MATCH(MAX(Count),Count,0),0)
Now I just need a way to merge that formula with this one;
=IF(AND(Dates >= DATE(2017,9,1), Dates <= DATE(2017,9,EOMONTH(9,0))),)
How do I pass the results of the =IF to the =OFFSET?

How to sum data within the same month?

I have a set of data which look like this:
A B C
1| Date | Value | Sum
2| 2014/08/03 10
3| 2014/08/02 7
4| 2014/08/01 5 todo
5| 2014/07/03 6
6| 2014/07/02 2
7| 2014/07/01 6 todo
8| 2014/06/03 1
9| 2014/06/02 4
10|2014/06/01 3 todo
Each cell on the Sum column has this part of code (will be autocompleted by dragging it down): IF(MONTH($A2)=MONTH($A3);"";"todo")
This would result in displaying text at each month's last line. The "todo" part would be replaced with code, which counts all values within the same month of "each last line", what would be the best way to do that?
In C2 enter:
=IF(MONTH(A2)=MONTH(A3),"",SUM($B$1:B2)-SUM($C$1:C1))
and copy down
For your example:

Resources