I have a requirement to bill for the isoweeks of occupation in the previous month. The weeks are tiered such that...
(tier1) week1 = 23
(tier2) week2 = 28
(tier3) week3 = 35
(tier4) week4+ = 46
I have provided a sample of the table below:
The Weeks column counts the number of weeks in the previous month from TODAY() [2022-11-29]. Also note that 1 isoweek is subtracted from the total should occupation rollover from month to month to avoid duplicated billing from before the previous month-this has already been accounted for in the Weeks column, I also account for the current tier in the Tier column (I'm hoping that these helpers assist with final result)
If we look at Id 1, this entity has a total occupation of 4 isoweeks (2022-09-21 to 2022-10-21) however the intention is to bill 2 isoweeks in month 10. This entity is currently in tier 4. The result should be 81 (35+46).
If we look at Id 4, this entity has a total occupation of 13 isoweeks (2022-08-09 to 2022-10-31... it's still in occupation as at the end of month 10) however the intention is to bill 5 isoweeks in month 10. This entity is currently in tier 4. The result should be 230 (46+46+46+46+46).
If we look at Id 6, this entity has a total occupation of 3 isoweeks (2022-10-05 to 2022-10-19) the intention here is to bill 3 isoweeks in month 10. This entity is currently in tier 3. The result should be 86 (23+28+35).
I hope this makes sense. I greatly appreciate any and all help!
EDIT: I have attempted SUMPRODUCT using an array but either I am doing it incorrectly or the function isn't designed to work for my issue.
Related
I'm new to python and new to pandas. Of course, if my project used exact dates, I could easily do this, but unfortunately, the date type is a little different, and as you can see, the sign 08 is after the year 1401, which means it is the eighth month of the year 1401.
I currently know that these 3 customers have bought from me this month. But I want to know if these 3 customers bought from me in the previous month or two months ago? If they do, I will give them a discount.
Of course, I should also say that the number 08 is not always fixed, but it could be 09 in the next month. I just want to know if they bought from me 1 month ago or not?
According to the picture, now only Sara should get a discount
You could convert the purchase date to an integer and calculate the number of months from there.
For instance, you have the purchase month 1901/07 and you want to know in 1901/08 how many months the last purchase took place. So you convert both values to integers and subtract them (190108 - 190107 = 1).
import pandas as pd
df = pd.DataFrame({'customer': ['david', 'sara'], 'date': ['1901/03', '1901/07']})
# Manually setting the reference month (190108 for Year 1901 and Month 08)
df['months'] = 190108 - df['date'].replace('/', '', regex=True).astype(int)
# Check if eligible for discount
df['discount'] = df['months'].isin([1, 2])
customer
date
months
discount
0
david
1901/03
5
False
1
sara
1901/07
1
True
To compare with today's month you could to the following:
df['months'] = int(pd.Timestamp.now().strftime('%Y%m'))\
- df['date'].replace('/', '', regex=True).astype(int)
I am new to spotfire so please bear with me. I have a simple problem i hope. I have a display that has well production vs time. All I need is count the number of active wells as a function of time. The number of wells in month 1 = 95 but as we approach month 60 only 3 wells are active.
The well name = API14
The columns that a plotted are Oil and Months , Line by API14
I have tried
UniqueCount([API14]) OVER (Intersect(All([Axis.Line]))) AS [Cumulative Count]
This one gave the total unique API14 over time (95 in this example - light blue line) and not the declining well count as a function of time. Any help?
Try:
UniqueCount([API14]) OVER (Intersect([MONTHS],All([Axis.Line])))
I hope I can explain this properly. I need to calculate occupancy time for a population of migratory animals. Occupancy is defined as the period, in days, between the first and last sighting of an individual in a given year between 1999 and 2015. A sample of the type of sighting data I am dealing with is pasted below. I need to be able to calculate the number of days between sightings within a year and NOT between the first and last sightings or between each sighting. Further, I need a value of "1" if the animal was only seen once in that year, rather than a value of "0".
So, for example, based on individual 37 in the data below, the results table would look something like
1999 - 0 2000 - 11 2001 - 40 2002 - 2 2003 - 0
1999 - 0
2000 - 11
2001 - 40
2002 - 1
2003 - 0
2004 - 52
2005 - 1
...and so on.
I have tried this series of equations but it does not return the right values for the years in which an animal was seen only once and it ignores any years prior to the first year seen.
in cell K2:
=DATE(YEAR(MIN($B$2:$J$2)),1,1)
in cell L2:
=IF(N(K2)=0,"",MAX(MAX(IF($B$2:$J$2=K2,$B$2:$J$2)),0))
in cell M2:
=IF(N(K2)=0,"",IF(MAX($B$2:$J$2)>DATE(YEAR(K2)+1,1,1),DATE(YEAR(K2)+1,1,1),""))
so if more than 1 year between sightings then it should be 0?
and is that more than "365 days a year" or if it is spotted 1 time 1. december and 1 time 1. januar then its still only spotted 1 time pr year...
I was able to find a solution using this equation in the cells immediately following the last sighting.
=IF(COUNTIFS($B2:$V2,">="&DATE(BE$1,1,1),$B2:$V2,"<="&DATE(BE$1,12,31))>0,LOOKUP(DATE(BE$1,12,31),$A2:$V2)-INDEX($A2:$V2,MATCH(DATE(BE$1,1,0),$A2:$V2)+1)+1,0)
I have a large spreadsheet in Excel 2013 with student records. Each row corresponds to one student registered in one course. The spreadsheet spans 5 years of student records. I am trying to create a pivot table that shows me the distinct count of students who have 6 or more courses as well as those with fewer than 6 courses.
One row has the following fields (and many more): Student
Number Academic Year Course ID Calculated Field (as
above)
The pivot table will count unique student courses (ie. John Doe in Course A). I have a calculated field in my main data that combines Academic Year (ex. 2015), student number (ex. 345987) and Course ID (ex. 195100) into a field like AY2015SN345987CS195100. So, if student 345987 takes 7 different courses in 2015, I want that to count as 7. Then I create my pivot table with rows: Academic Year and Student Number; Values are Distinct Count of Calculated Field
I have created a pivot table that calculates all distinct student courses into something like this:
Year # of Students
+2015 501
+2014 640
+2013 465
...
If I expand my pivot table a bit more to individual student number rows, it looks like this:
Year # of Students
2015 501
345987 7
123765 5
...
I can also create a value filter (i.e. distinct count of courses is greater than or equal to 6) applied to the Student Number, so I meet one of my criteria (ex. 6 or more) into something like this:
Year 6 or More
2015 356
2014 458
2013 290
I can also filter and get those with less than 6 courses.
However, what I really want is to show the distinct count of those students that have 6 or more courses in one year and the distinct count of those students that have less than 6 courses into a single pivot table.
The final product would look something like one of these:
Year 6 or More Less than 6
2015 356 145
2014 458 182
2013 290 175
Data summarization with greater than and less than – Excel-Formula & PivotTable
Assuming the DATA is located at range B6:D176 with the following fields as described by the user (adjust range as required):
Student : Student Number
Year : Academic Year
Course ID
Key : Calculated Field
Objectives :
Classify within each year in the database the student population in two groups:
a. Students with 6 or more courses
b. Students with less than 6 courses
Summarize both groups for each year, showing for every year and each group the total of students and total of student\courses
I’m not sure that all calculations needed can be performed by a PivotTable, therefore I propose to use working fields to do the calculations then a PivotTable to summarize the results.
Working Fields :
Key : Let’s take out of this calculation the Course Id in order to have a field that contains the Year\Student combination.
Enter this formula in E7 then copy till last record
=CONCATENATE("AY",$C7,"SN",$B7)
AY.SN.CS.Cnt : Count of Year\Student\Course. Enter this formula in F7 then copy till last record
=COUNTIF($E$6:$E$176,$E7)
AY.SN.Cnt : Count of Year\Student. Enter this formula in G7 then copy till last record
=1*(COUNTIF($E$6:$E7,$E7)=1)
AY.SN.CS >= 6 : Quantity of records for Year\Student with 6 or more courses. Enter this formula in H7 then copy till last record
=1*($F7>=6)
AY.SN.CS < 6 : Quantity of records for Year\Student with less than 6 courses. Enter this formula in I7 then copy till last record
=1*($F7<6)
AY.SN >= 6 : Quantity of Students with 6 or more courses in a Year. Enter this formula in J7 then copy till last record
=1*($F7>=6)*$G7
AY.SN < 6 : Quantity of Students with less than 6 courses in a Year. Enter this formula in K7 then copy till last record
=1*($F7<6)*$G7
Fig. 1
The working fields can be hidden if it’s preferable to the user
Then create a PivotTable as per figure below
Fig. 2
The PivotTable reads that in Year 2015 there are:
3 Students with 6 or more courses AY.SN >= 6 and a total of 22 courses AY.SN.CS >= 6
3 Students with less than 6 courses AY.SN < 6 and a total of 10 courses AY.SN.CS < 6
I'm trying to fix up a formula I have that's having some issues. It's supposed to track # days invoiced in a month, so the high-level idea is to take the maximum date in a month and subtract the minimum date in the month, and on error subtract the 1st day of the month. My current formula has issues adjust for invoices that may cross months, an example being 1/25 - 2/3 where if this were the only invoice, January should show 7 days invoiced and February would show 3. If there were another invoice from 2/15 - 2/28, I would want Feb to show the maxed invoice days, 14 in this example.
For reference here's what a table could look like:
A B C D E F
start month end month invoice begin invoice end Month Max Days invoiced
jan 1 feb 1 1/25/14 2/3/14 1/1 7
feb 1 feb 1 2/15/14 2/28/14 2/1 14
3/1
etc.........
I tried the formula below but it was erroring out, plus I don't think it will account for gaps in invoices like in my example.:
=IF(B2:B100=X1,MAX(D2:D100),) - IF(A2:A100=X2,MIN(C2:C100),A2)
'where column X is a list of months, X1 = 1/1, X2 = 2/1, etc.
No luck with this formula either, keeps erroring out and giving 0 values:
{=DATEDIF(IF(A2:A100=E2,MIN(C2:C100),),IF(B2:B100=E2,MAX(D2:D100),),"d")}
I appreciate your help!
Not sure exactly what you are looking for but you could probably make use of the EOMONTH() function. Here's an example of it:
=EOMONTH(A2,0)-A2+1
by the way - here is how you would get the start of the month:
=EOMONTH(TODAY(),-1)+1
Try the following per your comment below:
"I think this could be useful but I'm not sure it would work if the invoice end was, say, 2/21 or anytime before the EOM"
=IF(B3>=EOMONTH(A3,0),EOMONTH(A3,0)-A3+1,B3-A3+1)