JeanaBeana
JeanaBeana

Reputation: 1

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!

Upvotes: 0

Views: 575

Answers (1)

bknights
bknights

Reputation: 15377

You can do this with 31 formula fields.

  1. To avoid overlapping months add a formula text column with a formula TO_CHAR({trandate}, 'YYYY-MM')

  2. 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)

  3. 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)

  4. Set summary columns as follows:

    1. Sales Rep - Group
    2. Document Number - Count
    3. Formula Text - Group
    4. 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)

  1. 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
  2. Right click and select 'Inspect'. This opens the developer tools
  3. Find the 'console'. You should see some clear space at the bottom.
  4. Copy and paste the text below into the console and press your enter key.
  5. If all went well the script will print a number
  6. 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);

})

Upvotes: 1

Related Questions