I have a schedule that my team fills out daily in a google sheet. On a seperate tab, I would like a running count per day per schedule code per agent.
Linking a sample spreadsheet here. In this example, I'm trying to input a countif that returns
2019-01-27 T 5 6 0 4
2019-01-27 C 3.5 0 0 7
2019-01-27 LC 0 0 0 0
2019-01-27 S 0 0 0 0
2019-01-27 L 0.5 0 0 1
2019-01-27 M 0.5 0 0 1
2019-01-27 SP 0 0 0 0
2019-01-27 U 0 0 0 0
2019-01-27 MCX 2 0 0 2
2019-01-27 OCX 0 0 0 0
2019-01-27 TR 0 0 0 0
But I cannot for the life of me get a countifs function to work. Any help is much appreciated!
https://docs.google.com/spreadsheets/d/1gp0ZrcYLJfEnUHxgxagAl99X_MCjEIdvwFyfSdGngSE/edit?usp=sharing
Combine INDIRECT with MATCH:
=COUNTIF(INDIRECT("'Mon 1/27'!F"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)&":AG"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)),$B2)
INDIRECT
MATCH
Here is how it works:
MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0) will search the row number of the agent, referenced to cell A1
INDIRECT("'Mon 1/27'!A"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)&":AG"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)) will return a range referenced always to columns F and AF but with the row number returned in step 1, ie, F3:AG3,F4:AG4, and son.
COUNTIF will just count the criteria in the range from step 2.
Hope this helps.
IMPORTANT: In the expected output you posted, the MCX result for Barack Obama is 2, but my formula gets 4. Are you sure your output is right?
Related
need some help here.. I am looking to retrieve Gender from Sheet 2 corresponding to the name in Sheet 1.
Step 1 - Match the name in sheet 1 to sheet 2 (not all names in sheet 1 will be in sheet 2, mark NA for non matching names)
Step 2 - Look for the corresponding gender in sheet 2.
Step 3 - Retrieve the column header or the last number in the column header (1,2,3...6)
Sheet 1
Name
Gender
w
???
e
r
t
y
u
i
q
w
e
r
Sheet 2
Name
Male 1
Female 2
other 3
other 4
other 5
Do not know 6
w
1
0
0
0
0
0
a
0
0
0
0
0
1
q
1
0
0
0
0
0
r
0
1
0
0
0
0
e
1
0
0
0
0
0
t
0
0
0
0
1
0
y
0
0
0
0
0
1
u
0
1
0
0
0
0
with Office 365 we can use FILTER:
=IFERROR(FILTER($F$1:$K$1,INDEX($F$2:$K$9,MATCH(A2,$E$2:$E$9,0),0)=1),"No Match")
With older versions we can use another INDEX/MATCH:
=IFERROR(INDEX($F$1:$K$1,MATCH(1,INDEX($F$2:$K$9,MATCH(A2,$E$2:$E$9,0),0),0)),"No Match")
I have a dataset like this,
sample = {'Theme': ['never give a ten','interaction speed','no feedback,premium'],
'cat1': [0,0,0],
'cat2': [0,0,0],
'cat3': [0,0,0],
'cat4': [0,0,0]
}
pd.DataFrame(sample,columns = ['Theme','cat1','cat2','cat3','cat4'])
Theme cat1 cat2 cat3 cat4
0 never give a ten 0 0 0 0
1 interaction speed 0 0 0 0
2 no feedback,premium 0 0 0 0
Now, I need to replace the values in cat columns based on value in Theme. If the Theme column has 'never give a ten', then change cat1 as 1, similarly if the theme column has 'interaction speed', then change cat2 as 1, if the theme column has 'no feedback' in it, change 'cat3' as 1 and for 'premium' change cat4 as 1.
In this sample I have provided 4 categories, I have in total 21 categories. I can do if word in string 21 times for 21 categories, but I am looking for an efficient way to write this in a function, loop every row and go through the logic and update the corresponding columns, can anyone help please?
Thanks in advance.
Here is possible set columns names by categories with Series.str.get_dummies - columns names are sorted:
df1 = df['Theme'].str.get_dummies(',')
print (df1)
interaction speed never give a ten no feedback premium
0 0 1 0 0
1 1 0 0 0
2 0 0 1 1
If need first column in output add DataFrame.join:
df11 = df[['Theme']].join(df['Theme'].str.get_dummies(','))
print (df11)
Theme interaction speed never give a ten no feedback \
0 never give a ten 0 1 0
1 interaction speed 1 0 0
2 no feedback,premium 0 0 1
premium
0 0
1 0
2 1
If order of columns is important add DataFrame.reindex:
#removed posible duplicates with remain ordering
cols = dict.fromkeys([y for x in df['Theme'] for y in x.split(',')]).keys()
df2 = df['Theme'].str.get_dummies(',').reindex(cols, axis=1)
print (df2)
never give a ten interaction speed no feedback premium
0 1 0 0 0
1 0 1 0 0
2 0 0 1 1
cols = dict.fromkeys([y for x in df['Theme'] for y in x.split(',')]).keys()
df2 = df[['Theme']].join(df['Theme'].str.get_dummies(',').reindex(cols, axis=1))
print (df2)
Theme never give a ten interaction speed no feedback \
0 never give a ten 1 0 0
1 interaction speed 0 1 0
2 no feedback,premium 0 0 1
premium
0 0
1 0
2 1
I have this issue in excel where I want to delete 0 and re-stack the rows.
Problem:
0 0 1 2 3
0 0 0 1 0
0 2 3 0 1
2 5 3 0 0
The desired result would be
1 2 3
1 0
2 3 0 1
2 5 3 0 0
Any suggestions?
This will create a range from the first non 0 to the end and then the outer INDEX will return them in order as it is dragged across.
=IFERROR(INDEX(INDEX($A1:$E1,AGGREGATE(15,7,COLUMN($A1:$E1)/($A1:$E1<>0),1)):$E1,,COLUMN(A:A)),"")
Just for the sake of giving alternatives:
Formula in A6 translates to:
=IFERROR(INDEX($A1:$E1,,MATCH(TRUE,INDEX($A1:$E1>0,0),0)+COLUMN()-1),"")
Dragged down and sideways.
Sorry for bad english,
I've some cell with 0 value and 1 value in my microsoft excel, and i want to show 0 values with not valid and 1 values with valid without affecting the formula.
My current excel :
x A B C D E F
1 1 0 0 0 1 0
2 0 1 1 0 0 1
3 1 0 1 0 0 1
4 0 1 1 1 1 1
5 0 0 1 0 1 0
What i want :
valid notvalid notvalid notvalid valid notvalid
0 1 1 0 0 1
1 0 1 0 0 1
0 1 1 1 1 1
0 0 1 0 1 0
Use a custom number format (ctrl+1) of [Color13][=1]v\ali\d;[Color9][=0]\notv\ali\d;; on the cells.
In addition to the valid/notvalid display text, I've added dark blue font for the valids and dark red for notvalid.
Considering you are now working in Worksheet1, if you don't want to edit the formula you currently have in cells A1:F5, you can:
either go to/create Worksheet2 and select the cell A1 OR select the cell A7 in Worksheet1.
write in Worksheet1!A7 or Worksheet2!A1 the following formula:
=IF(Worksheet1!A1=1,"valid","notvalid")
copy the formula dragging the fill handle as needed.
I hope I understood well what you would like to do.
I've set up Names with the intention of using them to return data ranges for a line chart. The X values are "GI", "IE" and "EE". The Y value is "DATE".
However, my "DATE" and "GI" names are returning "#VALUE!" errors - whereas IE and EE are not.
So far, I have found that this error occurs when the height value (CountIf below) is more than 1.
The cell range, and beyond to 2000-and-something, are dynamically generated from user selections to form a Date Range. Ergo the use of CountIf rather than CountA.
Any help would be much appreciated. This is the last leg of a difficult workbook!
DATE:
=OFFSET(Graph!$B$8,0,0,COUNTIF(Graph!$B$8:$B$2927,">"&0)-1)
GI:
=OFFSET(Graph!$C$8,0,0,COUNTIF(Graph!$C$8:$C$2927,">"&0)-1)
IE:
=OFFSET(Graph!$D$8,0,0,COUNTIF(Graph!$D$8:$D$2927,">"&0)-1)
EE:
=OFFSET(Graph!$E$8,0,0,COUNTIF(Graph!$E$8:$E$2927,">"&0)-1)
Information:
B C D E
7 DATE GI IE EE
8 25/04/2011 0 0 0
9 26/04/2011 0 0 0
10 27/04/2011 0 0 0
11 28/04/2011 0 0 0
12 29/04/2011 0 0 0
13 30/04/2011 0 0 0
14 01/05/2011 0 0 0
15 02/05/2011 0 0 0
16 03/05/2011 0 0 0
17 04/05/2011 0 0 0
18 05/05/2011 0 0 0
19 06/05/2011 0 0 0
20 07/05/2011 0 0 0
21 08/05/2011 0 0 0
22 09/05/2011 0 0 0
23 10/05/2011 18000 0 0
24 11/05/2011 18000 0 0
25 12/05/2011 18000 0 0
26 13/05/2011 18000 0 0
27 14/05/2011 18000 0 0
28 15/05/2011 18000 0 0
29 16/05/2011 18000 0 0
30 17/05/2011 18000 0 0
31 18/05/2011 18000 0 0
32 19/05/2011 18000 0 0
33 20/05/2011 18000 0 0
34 21/05/2011 18000 0 0
35 22/05/2011 18000 0 0
This formula should create the correct named Range for date:
=OFFSET(Sheet1!$B$8,0,0,MATCH(Sheet1!$D$4,Sheet1!$B$8:$B$2927,0),1)
For GI:
=OFFSET(Sheet1!$B$8,0,1,MATCH(Sheet1!$D$4,Sheet1!$B$8:$B$2927,0),1)
For IE:
=OFFSET(Sheet1!$B$8,0,2,MATCH(Sheet1!$D$4,Sheet1!$B$8:$B$2927,0),1)
For EE:
=OFFSET(Sheet1!$B$8,0,3,MATCH(Sheet1!$D$4,Sheet1!$B$8:$B$2927,0),1)
(D4 contains the end date dropdown.)
In the data selection for the graph, it is important to write the named Range including the sheet it's on, e.g.: =Sheet1!nrDate instead of just =nrDate.
Please let me know if this works for you.
So based on your data, an going a slightly different route than offset (offset route should work) I used the index route.
for the x axis I used
=INDEX($B$9:$B$36,MATCH($C$5,$B$9:$B$36,0)):INDEX($B$9:$B$36,MATCH($D$5,$B$9:$B$36,0))
I used a defined name of X_axis
for the y axis I used
=INDEX($C$9:$C$36,MATCH($C$5,$B$9:$B$36,0)):INDEX($C$9:$C$36,MATCH($D$5,$B$9:$B$36,0))
I used a define name of Y_axis. For your second series on the Y axis, you would need to change the reference range from C9:C36, to the appropriate column that is lined up with your dates.
When defining the series, I had to use the workbook name in conjunction with the named range. so series data looked like this:
Proof of Concept