Determine number of days (not including weekend) based on hours given - excel

I have two important details that are inputted into an excel table, Job_Start_Date and Job_Hours (meaning the hours required to complete the job). Given certain working hours (eg 7:00am-3:30pm) I need to calculate what day and what time they will finish. I already have that basic bit working, but I cannot for the life of me figure out how to skip weekends in that calculation (Note that there is a boolean for Sat/Sun that defines whether that day should be skipped).
Here is an example of the data
and an example of the data visualization: (The DIV errors are because employee count equals 0, pay this no mind.)
.
This is the formula used in the visualizer (a massive index match)
=IFNA(INDEX(INDIRECT(Allocation!$A$1), MATCH(1,($A3 = INDIRECT(Allocation!$K$1))
* (C$1 >= INDIRECT(Allocation!$C$1)) * (C$1 <= INDIRECT(Allocation!$D$1))
* IF(C$1 = INDIRECT(Allocation!$C$1), ($B3 >= INDIRECT(Allocation!$E$1)),
($B3 >= INDIRECT(Allocation!$I$1))) * IF(C$1 = INDIRECT(Allocation!$D$1),
($B3 < INDIRECT(Allocation!$F$1)), ($B3 < INDIRECT(Allocation!$J$1))), 0)),"")
As you can see in the image, Saturdays need to be skipped (being FALSE), but it is still shown on the visualizer. However, if I include a statement that matches the Saturday condition (so it only shows up on a Saturday if TRUE), it will not alter the end date and thus will not push the final day to Monday.
Essentially the question is: How can I skip days but preserve the 'working hours'. This must be done in excel formulas in the same Job table (first image).
Thanks.

Here is how I got it working using WORKDAY.INTL.
First is a nested IF to determine which weekend type to use for the workday.intl function
Weekend=IF(OR([#[JOB SATURDAY]], [#[JOB SUNDAY]]), IF(AND([#[JOB SATURDAY]], [#[JOB SUNDAY]]), -1, IF([#[JOB SATURDAY]], 11, 17)), 1)
Then a second if statement that references that value and then spits out the correct date
=IF([#[Weekend]] = -1, [#[JOB START DATE]]+[#[Working Days]], WORKDAY.INTL([#[JOB START DATE]], [#[Working Days]], [#[Weekend]]))

Related

How can I extract a total count or sum of agents who made their first sale in a specified month?

I am trying to extract some data out of a large table of data in Excel. The table consists of the month, the agent's name, and either a 1 if they made a sale or a 0 if they did not.
What I would like to do is plug in a Month value into one cell, then have it spit out a count of how many agents made their first sale that month.
Sample Data and Input Output area
I found success by creating a secondary table for processing a minif and matching to agent name, then countif in that table's data how many sales months matched the input month. However I would like to not have a secondary table and do this all in one go.
=IF(MINIFS(E2ERawData[Date Group],E2ERawData[Agent],'Processed Data'!B4,E2ERawData[E2E Participation],1)=0,"No Sales",MINIFS(E2ERawData[Date Group],E2ERawData[Agent],'Processed Data'!B4,E2ERawData[E2E Participation],1))
=COUNTIFS(ProcessedData[Month of First E2E Sale],H4)
Formula in column F is:
=MAX(0;COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1)-SUM(COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;IF($A$2:$A$8=E3;$B$2:$B$8))))
This is how it works (we'll use 01/03/2022 as example)
COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1) This counts how many 1 there are for the proper month (in our example this part will return 2)
COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;SI($A$2:$A$8=E3;$B$2:$B$8)) will count how many 1 you got in previous months of the same agents (in our example, it will return 1)
Result from step 2, because it's an array formula, we sum up using SUM() (in our example, this return 1)
We do result from step 1 minus result from step 3 (so we get 1)
Finally, everything is inside a MAX function to avoid negative results (February would return -1 because there were no sales at all and agent B did a sale on January, so it would return -1. To avoid this, we force Excel to show biggest value between 0 and our calculation)
NOTE: Because it's an array formula, depending on your Excel version maybe you must introduce pressing CTRL+ENTER+SHIFT
If one has got access to the newest functions:
=LET(X,UNIQUE(C3:C9),VSTACK({"Month","Total of First time sales"},HSTACK(X,BYROW(X,LAMBDA(a,SUM((C3:C9=a)*(MINIFS(C3:C9,D3:D9,D3:D9,E3:E9,1)=C3:C9)))))))

Calculation with respect to dates is incorrect in oracle

I have to calculate some forumales based on Dates coming from table. For reference the exact value with formula is provided in Excel.
The formula and Excel answer is below.
Formula in Excel :
=IF(
D12>=DATE(2016,10,1),
(S12-T12)+(S12-T12)*2.5%
+(
IF(
ROUNDDOWN(YEARFRAC(DATE(2016,4,1),D12),0)=0,
0,
EFFECT(
(ROUNDDOWN(YEARFRAC(DATE(2016,4,1),D12),0)*2.5)%,
ROUNDDOWN(YEARFRAC(DATE(2016,4,1),D12),0)
)
)
)
*
((S12-T12)+((S12-T12)*2.5%)),
((S12-T12))
)
-(
IF(
AND(
D12>=DATE(2018,4,1),
D12<=DATE(2018,12,21),
E12<=DATE(2018,12,21)
),
7.69%*(S12-T12),
0
)
)
And the answer for which calculation in Excel is:- 30,153
and my answer coming is 28700/-
The value for D12 = 03/05/18 (dd/mm/yy) format, E12 = 21/04/19
S12 = 30000, T12 = 2000,
Here is my calculation logic provided in oracle.
IF TO_DATE(V_FINALSRDATE, 'dd-mm-yy') >= TO_DATE('01-10-2016', 'dd-mm-yy')
THEN
v_STD_REVISED_AMT := (V_STANDRD_AMT - v_OD_Discount) + (V_STANDRD_AMT - v_OD_Discount) * 2.5/ 100;
dbms_output.put_line( 'Standard revised amount 1: ' || v_STD_REVISED_AMT);
ELSE
v_STD_REVISED_AMT := (V_STANDRD_AMT - v_OD_Discount);
dbms_output.put_line( 'Standard revised amount 2: ' || v_STD_REVISED_AMT);
END IF;
Do I need to add one more IFELS part? Where is my logic failing?
Please help as where my logic is failing.
You are not doing the full calculation; you have calculated the (S12-T12)+(S12-T12)*2.5% but you have missed the second part of the calculation.
You need to implement an Oracle version of the YEARFRAC function using US (NASD) 30/360 day count basis (since you are not passing a 3rd argument to YEARFRAC) and then add in the second half of your Excel formula into your PL/SQL calculation.
If you want it to have the same behaviour as Excel then you will also need to implement all the bugs that Excel has as the documentation notes that:
The YEARFRAC function may return an incorrect result when using the US (NASD) 30/360 basis, and the start_date is the last day in February.
However, since the exact nature of the bug is not detailed, you will need to work out what the errors are and implement them yourself. But since you are using a start_date of 2016-04-01 then this may not apply (unless you also need to generalise this function for use elsewhere).
Alternatively, since you appear to be rounding the year fraction down to the nearest whole number then you are only calculating the number of full years between the dates and, instead of YEARFRAC, you could use:
EXTRACT( YEAR FROM (V_FINALSRDATE - DATE '2016-04-01') YEAR TO MONTH)
Or
FLOOR( MONTHS_BETWEEN( V_FINALSRDATE, DATE '2016-04-01' ) / 12 )

Power BI first IF-Statement then the DAX-Formula

I am new to Power BI and have the following issue:
I tried to build a formula for a frequency counter. I got some examples from the web and I was able to build this working formula. The basic idea behind is to categorize an item with the values: daily, weekly or first time.
I tried to add an IF-Statement to the formula, that is checking a calculated column "Time frame", which shows the duration of an item in minutes.
Basically it should run this formula only if the Column "Time frame" is equal or bigger 1.
Now the formula gives to items with a Time frame of 0, the value first time. But they should be ignored or blanked.
Calculated column =
Var freqcount =
COUNTAX(FILTER(ALL('Count'),
AND([Date]>=DATEADD('Count'[Date],-6,DAY)&&[Date]<=EARLIER([Date]),[ID]=EARLIER('Count'[ID]))),ID])
return
if(freqcount>=4,"Daily",if(freqcount>=2,"Weekly",if(freqcount>=1,"First time","Inactive")))
I would be thankful, if someone could support me with this issue.
Edit: an ID can occur multiple times in my table but with different dates. But only once with the same date. For example:
ID 1, Date 01.01.2020
ID 1, Date 02.01.2020
ID 1, Date 03.01.2020
it is easier to use calculate:
Calculated column =
var rDate = yourTable[Date]
var rID = yourTable[ID]
var freqCount = CALCULATE(yourTable('Count'), FILTER(yourTable, rDate >= DATEADD(yourTable[Date], -6 , DAY) && rID = yourTable[ID] && yourTable['Time frame'] > 0))
return if(freqcount>=4,"Daily",if(freqcount>=2,"Weekly",if(freqcount>=1,"First time","Inactive")))
you see how I simply added the Time frame to the expression. Also I removed the use of earlier by using var's so it is better readable.

Python3 Count Number of Week Days Ignoring Holidays

Testing one of my scripts it appears that Numpy busday_count includes Labor Day (September 2nd). Is there a way to disable the holidays?
print (np.busday_count('2019-08-31', '2019-09-02'))
Result = 0, but 9/2/2019 is clearly Labor Day and a Monday.
print (np.busday_count('2019-08-31', '2019-09-03'))
Result = 1, but it should be 2. As far as I know the formula excludes the first date but includes the second date. I also tried:
print (np.busday_count('2019-08-31', '2019-09-02', holidays=[]))
Result still = 0 despite attempt to clear any holidays. What am I missing?
As so often, the answer lies with the documentation and Python's love for half-open intervals:
Counts the number of valid days between begindates and enddates, not including the day of enddates.

PowerBI: How to calculate/convert Time into Percentage using DAX/Measure

I managed to get in Excel desired % of time difference from column E, easy job just changed the Data Type to Percentage. What are we calculating is % of these TimeDifferences, one per one (other columns inconsiderable).
The same thing isn't in PowerBI, where I am not able to calculate it properly, always getting "1" before comma and then the result - you can compare it in both tables/columns what I am talking about.
I am looking for the way/DAX/measure how to properly calculate it, no matter in decimals or directly to percentage, as long as the % is the same as in Excel column. Any ideas?
P.S Left is Excel and right is PowerBI!
Seems Excel is basing the percentage on 24 hours, this I used in the calculation (24 hours = 24 * 3600 seconds).
I started combining in power query the date and the time, this has to do with the fact that you go over the day and your calculation still needs to be correct.
Go to query editor. select both columns, combine them. Next change the type to Date/Time, result:
Save and close editor.
In Power Bi, add a column:
NextDate = LOOKUPVALUE(Explog[Date];Explog[Index];Explog[Index] + 1)
This is picking up the next Date based on Index + 1
Add another column TimeDiffSec, calculating the datediff in seconds:
TimeDiffSec = DATEDIFF(Explog[Date];Explog[NextDate];SECOND)
Last step is adding a column for percentage:
% of time difference =
var perc = Explog[TimeDiffSec]/ (24*3600)
return if(perc >= 1; perc - 1; perc)
End result:
Note: If you have a situation you do not want to mix the System (STYRAX - scrubber) you can use the following for the NextDate:
NextDate =
var nextIndex =
CALCULATE(MIN(Explog[Index]);
FILTER(Explog;Explog[Index] > EARLIER(Explog[Index]) && Explog[System] = EARLIER(Explog[System])))
return
LOOKUPVALUE(Explog[Date];Explog[Index];nextIndex; Explog[System];Explog[System])

Resources