Related
I have 2 tables and need to use criteria from table1 (Team) to look up information from Schedule2 (Team's Schedule for the year) and then use that array from Schedule2 to find the matches in table1 (opponents) and pair that with the criteria of matching the position within table 1 (position = position) to then sum up the associated numbers that match (2021 opp position points) to calculate the expected total points for the year.
In English: use the team to look up the schedule, use the schedule to look up the array of opponents the team has for the year, use the array of opponents for the year to find the opponents in table1, and then match the position of the current row to the position that is playing each of those opponents, and then sum up the associated points.
Goal: This is to calculate a forecast of each team's position's total points for the year based on how many points their opponents for the year are currently giving away to each position.
Explained Example: So if Dallas WR plays NYG, MIA, WAS, and MIA again, sum up the total points NYG, MIA, WAS, and MIA are currently giving to WRs they are currently play against.
FYI WR = Wide Receiver RB = Running Back, TE = Tight End D/ST = Defense string, QB = Quarterback
I can't use helper cells and need a single formula. Schedule2 will give duplicate values (Some teams play the same team twice and each of those values need to be calculated and not considered unique and not counted just once.
The current formula I have is below but it only seemed to work for one row and didnt work when I drug it down to the row below. could be a referencing issue but I didnt notice anything that would cause this.
The first part of the formula is meant to get the total for the non-duplicated values and the second is meant to get the duplicated values.
= SUM( IF( ISERROR( MATCH( Table1[[#All],[Position]],G14,0)
* MATCH(Table1[[#All],[Opponent]],INDEX(Schedule2,0,MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0)),0) ),
0,
Table1[[#All],[2021 Opp Position]]))
+ SUM( IF( ISERROR( MATCH( Table1[[#All],[Opponent]],
IF( COUNTIF( INDEX( Schedule2, 0, MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0) ), INDEX(Schedule2,0,MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0)))=2,
INDEX(Schedule2,0,MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0)),
""), 0 )
* MATCH(Table1[[#All],[Position]],G14,0)
* MATCH(Table1[[#All],[Opponent]],INDEX( Schedule2,
0,
MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0) ),0) ),
0,
Table1[[#All],[2021 Opp Position]] ) )
I need to mark the month with 1s when the patient was covered by some product. One dose provides coverage for 1 month. Also i would like to see the gaps in coverage.
Another detail is that quantity may affect months of coverage too. Lets say the quantity is 2, then patient is covered for next 2 months.
Right now I using df.loc which works with the first dose, but can't wrap my mind around how to calculate those gaps in coverage.
df = pd.DataFrame({'patient':['1','2','3','4','5','6','7'], 'dose1':['A','B','B','A','C','C','C'],
'qty1':[1,2,1,4,1,3,4],
'days_since_last_dose1':[0,0,0,0,0,0,0],
'dose2':['B','A','B','A','C','B','C'],
'qty2':[1,2,1,4,1,3,4],
'days_since_last_dose2':[23,56,120,43,30,15,60],
'dose3':['B','B','B','A','A','C','B'],
'qty3':[3,1,1,2,1,3,4],
'days_since_last_dose3':[44,22,67,150,76,32,21], 'M1':[0,0,0,0,0,0,0], 'M2':[0,0,0,0,0,0,0], 'M3':[0,0,0,0,0,0,0], 'M4':[0,0,0,0,0,0,0], 'M5':[0,0,0,0,0,0,0], 'M6':[0,0,0,0,0,0,0], 'M7':[0,0,0,0,0,0,0], 'M8':[0,0,0,0,0,0,0], 'M9':[0,0,0,0,0,0,0], 'M10':[0,0,0,0,0,0,0], 'M11':[0,0,0,0,0,0,0], 'M12':[0,0,0,0,0,0,0]})
prod_1 = ['A']
prod_2 = ['B']
prod_3 = ['C']
df.loc[(df['dose1'].isin(prod_1)) & (df['qty']==1), ('MONTH1')] = 1
For example patient got Dose_1 (qty=1), which got him covered for 30 days, and comes back for Dose_2 (qty=2) 120 days later. Now it should be represented as:
M1 = 1, M2 = 0, M3 = 0, M4 = 0, M5 = 1 (patient came back 120 days after the first dose + double qty), M6 = 1, M7 = 0, M8 = 0 and so on.
welcome to stackoverflow,
for i in range(len(df['patient'])): #for loop to separate each patient in a separate dict
newdict={}
for k,v in df.items():
newdict[str(k)]=v[i]
data.append(newdict)
for log in data: # for loop to add up the total quantities and assign months to 1
for dose in range(log['qty1']+log['qty2']+log['qty3']):
log[f'M{dose+1}']=1
df = pd.DataFrame.from_dict(data)
df = df.to_csv('doses.csv')
i enjoyed figuring this out.
so basically i separated each patient and then added up the qty and put that through a for loop which assigns one to the months within the range of the added up quantities i hope that's what you were aiming for.
Edit:
for i in range(len(df['patient'])):
newdict={}
for k,v in df.items():
newdict[str(k)]=v[i]
data.append(newdict)
for log in data:
for dose in range(1,log['qty1']+1):
log[f'M{dose}']=1
gap = 1 + round((log['days_since_last_dose2']/30)+0.5)
for dose in range(gap,(gap+log['qty2'])):
log[f'M{dose}']+=1
gap1 = 1 + round((log['days_since_last_dose3']/30)+0.5)+gap
for dose in range(gap1,gap1+log['qty3']):
log[f'M{dose}']+=1
ok so i found the algorithm to calculate coverage, 2 indicates overlap in coverage.
I am attempting to build a saved search that measures our inventory cycle counts. I am using the saved transaction search to do this. I have been able to build out everything I want with the exception of Count Accuracy.
Here is what I have:
sum(Case when {transactionlinetype} = 'Adjusted Quantity' then abs({quantity}) Else 0 END) /
sum(Case when {transactionlinetype} = 'Snapshot Quantity' then {quantity} Else 0 END)
The goal is to get the % value of Item counted and divide it by the number of issues.
To provide the working example: I have 10 items to count, each item has 10 on hand so I have 100 items counted, 3 of those items had issues so my result should be 3%
I have looked for answers but have not been successful.
You don't say what result you're getting, or what the error is, but when I tried with your formula I got a 'possible divide by 0' error. The solution to this is to wrap the denominator in a nullif() function, so you could use:
sum(Case when {transactionlinetype} = 'Adjusted Quantity' then abs({quantity}) Else 0 END) /
nullif(sum(Case when {transactionlinetype} = 'Snapshot Quantity' then {quantity} Else 0 END),0)
What you are trying to do is like a subquery which is not possible in NS saved search.
I made a small workbook that exactly mimics the original formulas I posted. The purpose of the workbook is to calculate the bonuses for each employee based on various inputted combinations (listed below). Here is how my workbook is laid out:
Data Tab
Bonus Tab
Base Bonus Tab
Summary Tab
Picture of the Data tab that I utilize to input the different combinations:
Data Tab
List of the combinations:
Employee % (cell B3) & Company % (cell B4) cells have numbers inputted = Combo 1 (range: 0%-100%)
Employee $ (cell B5) & Company $ (cell B6) cells have numbers inputted =Combo 2 (range: $0-no limit)
Base Salary (B2) is Yes & Employee % (cell B3) cells have been inputted = Combo 3 (Base Salary is either Yes or blank)
Base Salary (B2) is Yes & Job Title (A8) & Employee % (cell B8) cell have been inputted = Combo 5
I use cell C1 for an IF statement to dictate which formula to use based on the combinations above. (ex. numbers in B5 & B6 = 1)
=IF(AND($B$2<>"",$A$8<>"",$B$8<>""),5,IF(AND($B$2<>"",$B$3<>""),3,IF($B$3<>"",1,IF($B$5<>"",2))))
Picture of the Bonus Tab: Bonus Tab
Picture of the Base Bonus Tab: Base Bonus Tab
Picture of the Summary Tab: Summary Tab
I have created formulas for each combinations separately, but as soon as I try to combine them into one, I get the Too many arguments error message since combo 3 & combo 5 use false within the IF statement. I am attempting to avoid making a calculations table and would prefer utilizing one formula on the summary tab by employee in column B.
I will further explain combo 3 specifically - If the base bonus is less than the regular bonus, than multiply the base bonus * Employee % + Company&Vendor bonus * Company %. If base bonus is more than regular bonus, than multiply regular bonus * Employee % + Company&Vendor bonus * Company %.
Example:
Bobby
Base Bonus $50 < Regular Bonus $100
$50 * 50% employee % = $25
+ $200 company + $0 vendor * 50% company = $100
Final answer is $125 if base bonus if < regular bonus
I will further explain combo 5 specifically - If the base bonus is less than the regular bonus, than multiply the base bonus * employees job title Employee % + Company&Vendor bonus * job title Company %. If base bonus is more than regular bonus, than multiply regular bonus * employees job title Employee % + Company&Vendor bonus * job title Company %.
Example:
Bobby
Base Bonus $50 < Regular Bonus $100
Find Bobby's Job title to determine Employee % & Company %
75% Employee % for Officers and 50% Company %
75% * $50 + 50% * ($200 Company & $0 Vendor) = $137.5
Final answer is $137.5 of base bonus if < regular bonus
Here is list of each formula by combo:
Combo 1:
=IF(Data!$C$1=1,Data!$B$3*Bonus!D2+Data!$B$4*(Bonus!E2+Bonus!F2))
Combo 2:
=IF(Data!$C$1=2,IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$6+Data!B5))
Combo 3:
=IF(Data!$C$1=3,IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2),VLOOKUP(A2,Bonus!$A$2:$D$5,4,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2)))
Combo 5:
IF(Data!$C$1=5,IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!E2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE),VLOOKUP(A2,Bonus!$A$2:$D$5,4,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!E2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE)))
Hopefully this is a lot more clear than my initial post and can easily be replicated. Let me know if you have any questions, Thank you!
I found some issues in your formulas
Combo3 In the else option you have A2 following the pattern it should be Summary!A2
Combo5 the sum is in the same cell you have (Bonus!E2+Bonus!E2) it should be (Bonus!E2+Bonus!F2)
I didn't record the initial nested If to compare why it is not working. I got this:
Final Nested:
=IF(Data!$C$1=1,Data!$B$3*Bonus!D2+Data!$B$4*(Bonus!E2+Bonus!F2),IF(Data!$C$1=2,IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$6+Data!B5,IF(Data!$C$1=3,IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2),VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2)),IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!F2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE),VLOOKUP(B2,Bonus!$A$2:$D$5,4,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!F2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE)))))
All data are coming from one table. Date is based on the creation_date field of the table. I would like to create a report similar to the example below:
No. Prior to No. On
10/01/2015 10/1/2015 Total No.
a 5 1 6
b 10 3 13
c 1 0 1
I could not figure out how to display the combine results on the same "Report Page". I have to create 2 report pages one is for the prior date and the other is for the date "on".
Ok. If I understand your data correctly do this.
In your report create query with query items:
Type (a,b,c etc)
[No. Prior to 10/01/2015] with Aggregate Function = 'Total' and with expression
case when creation_date < to_date('10/01/2015', 'DD/MM/YYYY')
then 1 else 0 end
[No. On 10/1/2015] with Aggregate Function = 'Total' and expression
case when creation_date >= to_date('10/01/2015', 'DD/MM/YYYY')
then 1 else 0 end
[Total No.] with expression
[No. Prior to 10/01/2015] + [No. On 10/1/2015]
And create simple table with this values.
Or you can try to do it with crosstab.