Complex nested IFS in excel - excel

So I have this output to track my tickets system that has the following columns:
1. create date
2. resolved date
3. location (A,B,C,D)
4. item (1,2,3,4)
How do I create a formula that could give me an output of average days open of an item in a week?
For example, week 32 of the year 2015, what is the average days open of item categorized '1' in location 'A'?
This shoudl be equal (total days open of all ticket '1')/(total tickets open of item '1') assuming I already know the total ticket opens.
And (resolved_date) – (create_date) if (last day of week) > (resolved_date), this indicates ticket is resolved within report week; = (last day of report week) – (create_date) if (last day of report week) < (resolved_date), this indicate ticket is resolved after report week; = (last day of report week) – (create_date) if resolved_date = null, this indicates ticket is not resolved by now.
I am thinking of a nested ifs formula like this IF( condition1, value_if_true1, IF( condition2, value_if_true2, value_if_false2 )) but not familiar with Excel enough to construct one.
Thanks!

Given what you've said, in my opinion it would be easier to break the data down into understandable steps. See the attached. I created some random data and a way to see by location and item the metric you describe at the beginning of any given work week. I'd recommend having Col A - D be the items you describe as 1-4 then make a columns adjascent E - H.
A = Create Date
B = Resolved Date
C = Location
D = Item
Formulas in each columns, row 2:
E: =IF($K$8>B2,"Closed",IF(A2<$K$8,"Open","Not Yet Open"))
F: =C2&D2
G: =IF(AND($F2=$K$5,$K$8>A2),1,0)
H: =IF(AND($F2=$K$5,$E2="Open"),$K$8-A2,0)
Make a menus tab. In column A put Locations in Cell A1, then all locations beneath it. Select the locations, including the header and hit Ctrl + Shift + F3. This will name the range of locations (Menus!A2:An), Locations. Do the same thing with Items in Column B. Now we can make some data validations. Now make a calendar tab. Put the first day of each WW in one column and the WW label in the next column. For example (12/28/2014 might be the first day of WW1). Add 7 the first date cell and drag it down. Drag the WW1 cell down to make it corresponding. Name the WW range 'WW'. Select the dates and the corresponding WW labels and name that 2-column range 'Calendar'
Head back to the page with your data. And do the following:
Location: (K3) Data Validation, List, Range =Locations
Item: (K4) Data Validation, List, Range =Items
Location + Item: (K5) =K3&K4
Work Week: (K7) Data Validation, List, Range =WW
First Day: (K8) =INDEX(Calendar,MATCH(K7,WW,0),1)
Total Days Open: (K10) =SUM(H:H)
Total Tickets: (K11) =SUM(G:G)
Avg Days Open: (K12) =K10/K11
Now you should be able to select the Location and item with drop downs and then a work week and get your metric.

Related

NetSuite formula for dates without transactions

I’m trying to create a report that has everyday of the month listed as a column and sums the transaction quantity for that day if transactions exist and enters a 0 in the column if no transactions exist for that day.
Example:
Day
1 2 3 … 28 29 30 31
Sales Rep.
John Doe. 5 0 0… 10 15 0 30
Any ideas how to make this work? I thought about extracting the day from the transaction date but I can’t figure out how to get the days without any transactions. I thought about using current date to extract day but then the formulas would change every day. Ugh!! Help me please!
You can do this with 31 formula fields.
To avoid overlapping months add a formula text column with a formula TO_CHAR({trandate}, 'YYYY-MM')
Create a saved search on sales orders that filters to the month of interest and includes sales rep, date, document number and amount (at least)
for each date you want to report on include a formula numberic column with a formula like case when TO_number(TO_CHAR({trandate}, 'DD')) = 14 then {amount} else 0 end. Give it a custom label of the day number (e.g. 14)
Set summary columns as follows:
Sales Rep - Group
Document Number - Count
Formula Text - Group
each Formula Numeric - Sum
That's all you need to do but the 31 formula columns are tedious so when I do this sort of thing I do the following to create a template of the saved search and then add and adjust the date range (e.g. add filters in the displayed filter region)
Open any scripted record. Usually just view a sales order. If the step below fails try in a sales order in Edit mode. You won't be saving or updating the order
Right click and select 'Inspect'. This opens the developer tools
Find the 'console'. You should see some clear space at the bottom.
Copy and paste the text below into the console and press your enter key.
If all went well the script will print a number
You can then take the search title (Daily Rep Sales in the example code) and paste it in the NS global search. If you run the search you'll see the last 30 days of sales totalled by rep. Add and update filters (e.g. for different date ranges or only for last month or only for this month etc) and then make the search public to share it (or share it with certain users etc)
require(['N/search'], search =>{
var dateCols = [];
for(var i = 1; i< 32; i++){
dateCols.push(search.createColumn({
name:'formulanumeric',
summary:search.Summary.SUM,
label:'Day '+ i,
formula: "case when TO_number(TO_CHAR({trandate}, 'DD')) = "+ i + " then {amount} else 0 end"
}));
}
const searchId = search.create({
type:'salesorder',
title:'Daily Rep Sales',
filters:[
['mainline', 'is', 'T'], 'AND',
['trandate', 'onorafter', 'daysago30']
],
columns:[
search.createColumn({name:'formulatext', formula:"TO_CHAR({trandate}, 'YYYY-MM')", summary:search.Summary.GROUP}),
search.createColumn({name:'salesrep', summary:search.Summary.GROUP}),
search.createColumn({name:'tranid', summary:search.Summary.COUNT}),
search.createColumn({name:'trandate'}),
search.createColumn({name:'amount'})
// whatever drill down fields you want without summary
].concat(dateCols)
}).save();
console.log(searchId);
})

Moving average excluding weekends and holidays

I have a table within PowerPivot currently that tracks a count of customers through our sales pipeline. From (by sales location) first interaction to charged sale. So far, I’ve creates a moving 5-day average that averages each task. Below is the DAX formula I’ve created thus far and an example table.
=
CALCULATE (
SUM ( [Daily Count] ),
DATESINPERIOD ( Table1[Date], LASTDATE ( Table1[Date] ), -7, DAY ),
ALLEXCEPT ( Table1, Table1[Sales Location], Table1[Group] )
)
/ 5
Where I’m struggling is being able to come up with a way to exclude weekends and company observed holidays. Additionally, if a holiday falls on a weekday I would like to remove that from the average and go back an additional day (to smooth the trend).
For example, on 11/26/18 (the Monday after Thanksgiving and Black Friday) I would like to average the five business days previous (11/26/18, 11/21-11/19, and 11/16). In the example above, the moving total and average for the previous 5 days should be Intake = 41 (total) 8.2 (average), Appointment = 30 (total) 6 (average), and Sale = 13 (total) and 2.6 (average).
Based on the formula currently, each of these numbers is inaccurate. Is there an easy way to exclude these days?
Side note: I’ve created an ancillary table with all holidays that is related to the sales data that I have.
Thank you for the help!
For this, I'd recommend using a calendar table related to Table1 on the Date column that also has a column IsWorkday with 1 if that day is a workday and 0 otherwise.
Once you have that set up, you can write a measure like this:
Moving Avg =
VAR Last5Workdays =
SELECTCOLUMNS (
TOPN (
5,
FILTER (
DateTable,
DateTable[Date] <= EARLIER ( Table1[Date] )
&& DateTable[IsWorkday] = 1
),
DateTable[Date], DESC
),
"Workday", DateTable[Date]
)
RETURN
CALCULATE (
SUM ( Table1[Daily Count] ),
Table1[Date] IN Last5Workdays
ALLEXCEPT ( Table1, Table1[Sales Location], Table1[Group] ),
)
/ 5
The TOPN function here returns the top 5 rows of the DateTable where each row must be a workday that is less than or equal to the date in your current Table1 row (the EARLIER function refers to the earlier row context that defines the current row).
I then use SELECTCOLUMNS to turn this table into a list by selecting a single column (which I've named Workday). From there, it's basically your measure with the date filter changed a bit.
#alexisolson Thank you for the response here. I was actually able to figure this out over the weekend but forgot to close out the thread (sorry about that! Appreciate your help either way). But I did something fairly similar to what you mentioned above.
I created a date table (CorpCalendar) that was only inclusive of working days. Then I created an index column within the CorpCalendar table to give each row a unique number in ascending order. From there, I linked the CorpCalendar table to my SalesData table by related dates and used the LOOKUPVALUE function to bring the index value over from the CorpCalendar table to the SalesData table. In a separate column I subtracted 4 from the date index value to get an index adjustment column (for a range of five days from the actual date index and the adjustment...if that makes sense). I then added an additional LOOKUPVALUE helper column to match the adjusted date index column to the appropriate working day.Lastly, I then used the following function to get the 5 day rolling average.
=CALCULATE(sum(Combined[Daily Count]),DATESBETWEEN(Combined[Date - Adjusted],Combined[Date - Adjusted (-5)],Combined[Date - Adjusted]),ALLEXCEPT(Combined,Combined[Group]))/5
This is probably more convoluted than necessary, however, it got me to the answer I was looking for. Let me know if this makes sense and if you have any suggestions for future scenarios like this.
Thanks again!

Combining formula using and / or in excel

Case 1
I have a set of data which i need to determine if the cell is in Business Hours or Not.
8 - 18 (08:00 - 18:00) Business Hours (BH)
outside the timeframe is Non Business Hours (NBH)
Given Cell value for example is = "7" (which is NBH)
here is the formula i created =if(AND(C2>=8,C2<=18 ),"BH","NBH")
Case 2
I have a set of data for days in a week, i need to determine if the cell is in Weekdays or Weekends.
I have this formula = =if(OR(I2="Saturday", I2="Sunday"), "NBH", "BH")
note : i used the same variable name NBH - Weekends , BH - Weekdays
What I really need to do is to combine those two cases into 1 formula.
I need to output these scenarios correctly, listing below :
Time is 08:00, date is Saturday/Sunday = Combined formula of case 1 and 2 should output "NBH"
Time is 07:00, date is Monday-Friday = Combined formula of case 1 and 2 should output "NBH"
Time is 12:00, date is Monday-Friday = Combined formula of case 1 and 2 should output "BH"
Formulas can be seen in column BH/NBH WEEKDAYS and BH/NBH Weekends, you can browse attached file thanks much!
Click to access the file
If you want to calculate it directly on the initital values:
=IF(OR(H2="Saturday", H2="Sunday", B2>18, B2<8), "NBH", "BH")
p.s. Alternatively you can combine the already calculated columns, if you intend to keep these columns:
=IF(AND((E2="BH"), (D2="BH")), "BH", "NBH")

DAX Calculation with Datesbetween Ignores all Datefilters

I am starting with DAX.
I have a standard date table and a table with sales. When I try to show the running total with the below formula the month filter is ignored, as shown:
The formula is:
Prov YTD VJ 2:=CALCULATE(FIRMPROV[SumProv];
All(Kalender[Jahr]);
DATESBETWEEN(Kalender[Datum];
Min(START_YTD[start_ytd]);
MIN(END_YTD[end_ytd])))
A good way to calculate running totals is by using the FILTER and EARLIER functions, but a prerequisite to that is that you need to create a Month Number column (ie. Jan = 1, Feb = 2, Mar = 3, etc.)
Then, you can use the following DAX:
CALCULATE(SUM([SumProv]),ALL(FirmProv),FILTER(FirmProv,[Month Number]<=EARLIER([Month Number])))
EARLIER basically is DAX's way of interpreting the current row. You're telling DAX to sum ALL of the rows in the FirmProv table where the month number is less than or equal to the current row (AKA running total).
Here's the result (note the numbers aren't exactly like yours, I just quickly mocked it up to show the example):

Sum of Averages in Excel Pivot Table

I am measuring room utilization (time used/time available) from a data dump. Each row contains the available time for the day and the time used for a particular case.
The image is a simplified version of the data.
If you read the yellow and green highlights (Room 1):
In room 1, there are 200 available minutes on 1/1/2016.
Case 1 took 60 minutes, case 2 took 50 minutes.
There are 500 available minutes on 1/2/2016, and only one case occurred that day, using 350 minutes.
Room 1 utilization = (60 + 50 + 350)/(200 + 500)
The problem with summing the available time is that it double counts the 200 minutes for 1/1/2016, giving: Utilization = (60+50+350)/(200+200+500)
There are hundreds of rows in this data (and there will be multiple data dumps of differing #'s of rows) with multiple cases occurring each day.
I am trying to use a pivot table, but I cannot obtain the 'sum of averages' for a particular room (see image). I am using a macro to pull the numbers out of the grand total column.
Is this possible? Do you see another way to obtain utilization?
(note: there are lots of other columns in the data, like case start, case end, day of week, etc, that are not used in this calculation but are available)
The reason that you're getting 300 for both Average of Available Time columns is because the grand total is a grand total based on the overall average and not a sum of the averages.
Room 1: 200 + 200 + 500 / 3 = 300
Room 2: 300 + 300 + 300 / 3 = 300
I could not comment on the original question, so my solution is based on a few assumptions.
Assumption #1: The data will always be grouped. E.G. All cases in room 1 on a given day will grouped in sequential rows.
Assumption #2: The available time column is a single value for the whole day, there will never be differing available times on the same day.
Solution: Use column E as the Actual Available Time. This column will use a formula to determine if the current row has a unique combination (Date + Room + Available Time) to the previous and if so, the cell will contain that row's available time.
Formula to use in E2:
=IF(AND($A1 = $A2, $B1 = $B2, $C1 = $C2), 0, $C2)
Extend the formula as far down as necessary and then include the new column in your PivotTable data range.
End Result
I created a unique reference by combining columns and then used sumif/countif/countif.
So the formula in column E would be:
=sumif(colB,cellB,ColC)/Countif(colB,cellE)/Countif(colB,cellE)
Doesn't matter if the data is in order or not then.
Extend the formula as far down as necessary and then include the new column in your PivotTable data range.
The easiest method I would recommend is this.
=SUM(H:H)-GETPIVOTDATA("Average of Available Time",$G$3)
The first term sums the H column, and the second term subtracts the grand total value. It is a dynamic solution, and will change to fit the size of the pivot table.
My assumptions are that the Pivot Table was originally placed in cell G3.

Resources