NetSuite formula for dates without transactions - netsuite

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

Related

Count number of sporadic events matched to reoccuring events [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.

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")

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.

How do I get the Month End Personal Time Off Days used?

Using the Start Date and End Date of PTO - Personal Time Off Days Used only count days used up to end of prior month, excluding weekends and U.S Holidays in that certain month. Example of a Holiday is Sept 7th 2015 in the United States.
My goals are:
Create a Data Item Month End Personal Time Off Days used.
Of course it should be getting the number of PTO Days USED from the prior month only.
Exclude weekends in that certain month. So if the Resource takes a Leave on Friday and Monday, Saturday and Sunday should not be excluded in the computation.
How to exclude U.S Holidays, if this is possible that's great but if it's not possible then I'm okay with numbers 1, 2 and 3.
I have created a Data Item column that captures the PTO days used. But this is good for Year to date.
Case when [PTO Info].[PTO Audit].[PTOAuditTypeId] = 31571
and [PTO Info].[PTO Audit].[TimeOffTypeId] = 31566
then [PTO Info].[PTO Audit].[PTODays]
when [PTO Info].[PTO Audit].[PTOAuditTypeId]=31572
and [PTO Info].[PTO Audit].[TimeOffTypeId] = 31566
and [PTO Info].[PTO Audit].[PTODays] < 0
then abs([PTO Info].[PTO Audit].[PTODays] )
else 0 end
I'm not sure if the query below can help.
A calendar table is really going to help you out here. Assuming it has one record per calendar date, you can use this table to note weekends, holidays, fiscal periods vs Calendar periods, beginning of month/end of month dates. A number of things that can help simplify your date based queries.
See this question here for an example on creating a calendar table.
The main point is to create a data set with 1 record per date, with information about each date including Month, Day of Week, Holiday status, etc.
Without a calendar table, you can use database functions to generate your set of dates on the fly.
Getting the Month number for a date can be done with
extract([Month], <date field goes here> )
Getting a list of values from nothing will be required to generate your list of dates (if you don't have a calendar table with 1 record per date to use) will vary depending on your source database. In oracle I use a 'select from all_objects' type query to achieve this.
An example from Ask Tom:
select to_date(:start_date,'dd-mon-yyyy') + rownum -1
from all_objects
where rownum <=
to_date(:end_date,'dd-mon-yyyy')-to_date(:start_date,'dd-mon-yyyy')+1
For Sql Server refer to this stackoverflow question here.
Once you have a data set with your calendar type information, you can join it to your query above:
join mycalendar cal on cal.date >= c.PTOStartDate
and cal.date <= c.PTOEndDate
Also note, _add_days is a Cognos function. When building your source queries, try and use Native functions, like in oracle you can 'c.PTOStartDate + a.PTODays'. Mixing Cognos functions with native functions will sometime force parts of your queries to be processed locally on the Cognos server. Generally speaking, the more work that happens on the database, the faster your reports will run.
Once you have joined to the calendar data, you are going to have your records multiplied out so that you have 1 record per date. (You would not want to be doing any summary math on PTODays here, as it will be inflated.)
Now you can add clauses to track your rules.
where cal.Day_Of_Week between 2 and 6
and cal.Is_Holiday = 'N'
Now if you are pulling a specific month, you can add that to the criteria:
and cal.CalendarPeriod = '201508'
Or if you are covering a longer period, but wanting to report a summary per month, you can group by month.
Final query could look something like this:
select c.UserID, cal.CalendarPeriod, count(*) PTO_Days
from dbo.PTOCalendar c
join myCalendar cal on on cal.date >= c.PTOStartDate
and cal.date <= c.PTOEndDate
where cal.day_of_week between 2 and 6
and cal.Is_Holiday = 'N'
group by c.UserID, cal.CalendarPeriod
So if employee with UserID 1234 Took a 7 day vacation from thursday June 25th to Friday July 3th, that covered 9 days, the result you get here will be:
1234 201506 4
1234 201507 3
You can join these results to your final query above to track days off per month.

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