Count number of sporadic events matched to reoccuring events [excel] - excel

I have two tables of different length:
a table of monthly data (e.g.: value of inventory at start of month)
a table of sporadic events which happened at random point throughout the year (e.g.: truck delivery to storage)
In table one, I would like to count in an extra column, the number of events from table 2 that occurred in that month. The table with the value of the inventory would show a count per row of how many trucks were unloaded.
I've been fighting with countifs but I just cannot get it to work due to different table lengths, the weird way to enter criteria etc.
I've tried to match the month and year of a truck delivery with the period in the inventory table.
=COUNTIFS(
<range: Dates of Truck deliveries from Table2>, "=MONTH(" &
<cellOfInventoryDate> & ")",
<range: Dates of Truck deliveries from Table2>, "=Year(" &
<cellOfInventoryDate> & ")")
I have a feeling there is a simple solution to this an dI just hit a wall.
Thanks
Table
1 - Inventory at start of month
01/01/2015 1000
01/02/2015 1200
01/03/2015 1100
01/04/2015 900
...
Table 2 - Date of Truck Delivery
01/01/2015
04/02/2015
07/02/2015
03/04/2015
11/07/2015

Ok, so here the answer.
I created a helper column in Table 2 which normalises the dates to the first of the month
=EOMONTH(cellwithdate,-1)+1
then I used countif (not countifs) to count when the date of the inventory matches the helper column.
=COUNTIF(helpercolumn, dateOfInventory)
this then counts how many deliveries were made in the month of that inventory's month.

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);
})

Dax Rolling Average with multiple records per day

Take a simple table
SalesTime
Product
UnitsSold
There is one row per sale. So there are multiple rows per day. I need a chart that will show the average units sold per sale over 7 days and average units sold per day over 7 days.
The examples that I found all used DATESBETWEEN or DATESINPERIOD and those throw an error if the table has multiple records per date.
I will name this table Sales and assume that Sales[SalesTime] is a date type rather than a datetime type. If not, create a new calculated column
Sales[SalesDate] = Sales[SalesTime].[Date]
and work with that instead.
Your rolling average units per sale can be calculated something like this:
AvgUnitsPerSale =
VAR CurrDay = MIN(Sales[SalesTime])
RETURN CALCULATE(
AVERAGE(Sales[UnitsSold]),
DATESBETWEEN(Sales[SalesTime], CurrDay-7, CurrDay))
You can get an average count of sales per day by using COUNT instead of AVERAGE. To get the average units sold per day, multiply the average count of sales and the average units per sale.

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.

Complex nested IFS in 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.

Excel 2010 Dax Onhand Quantity Vs. Last Date Qty

Ive spent the last 2 days trying to get this, and I really just need a few pointers. Im using Excel 2010 w/ Power Pivot and calculating inventories. I am trying to get the amount sold between 2 dates. I recorded the quantity on hand if the item was in stock.
Item # Day Date Qty
Black Thursday 11/6/2014 2
Blue Thursday 11/6/2014 3
Green Thursday 11/6/2014 3
Black Friday 11/7/2014 2
Green Friday 11/7/2014 2
Black Monday 11/10/2014 3
Blue Monday 11/10/2014 4
Green Monday 11/10/2014 3
Is there a way to do this in dax? I may have to go back and calculate the differences for each record in excel, but Id like to avoid that if possible.
Somethings that have made this hard for me.
1) I only record the inventory Mon-Fri. I am not sure this will always be the case so i'd like to avoid a dependency on this being only weekdays.
2) When there is none in stock, I dont have a record for that day
Ive tried, CALCULATE with dateadd and it gave me results nearly right, but it ended up filtering out some of the results. Really was odd, but almost right.
Any Help is appreciated.
Bryan, this may not totally answer your question as there are a couple of things that aren't totally clear to me but it should give you a start and I'm happy to expand my answer if you provide further info.
One 'pattern' you can use involves the TOPN function which when used with the parameter n=1 can return the earliest or latest value from a table that it sorts by dates and can be filtered to be earlier/later than dates specified.
For this example I am using a 'disconnected' date table from which the user would select the two dates required in a slicer or report filter:
=
CALCULATE (
SUM ( inventory[Qty] ),
TOPN (
1,
FILTER ( inventory, inventory[Date] <= MAX ( dates[Date] ) ),
inventory[Date],
0
)
)
In this case the TOPN returns a single row table of the latest date earlier than or equal to the latest date provided. The 1st argument in the TOPN specifies the number of rows, the second the table to use, the 3rd the column to sort on and the 4th says to sort descending.
From here it is straightforward to adapt this for a second measure that finds the value for the latest date before or equal to the earliest date selected (i.e. swap MIN for MAX in MAX(dates[Date])).
Hope this helps.
Jacob
*prettified using daxformatter.com

Resources