Vlookup on another table with multiple criteria - excel

Hi,
I have a list of payments and a table with the promises that collection officers made.
I want assign into the payment table by id (and date) the last collection officer that made the agreement with the debtor.
For example: On id 1111 there were two promises made: by Morticia Adams and Gulliver; But i choose Gulliver because he made the last promise in that date range taking in account the date of payment.
Likewise for id 5425 the last promise made was made by Marie Anne because 23.10.2016 (date of payment) is between 12.10.2016 and 26.10.2016 (promise dates).
I would be really grateful if somebody could guide me through this.
Thanks you!

Disclaimer: this formula generates what OP is describing, not what the picture is showing.
One way to do this is by finding the latest conversation date that satisfies the conditions:
The payment ID of the row in the promises table is equal to the payment id of the payments table.
The date of the payment is greater than or equal to the conversation date.
The date of the payment is less than or equal to the agreed payment date.
Which we can do like this:
{=MAX(($A$3:$A$8 = A12) * (B12 >= $B$3:$B$8) * (B12 <= $C$3:$C$8) * $B$3:$B$8)}
And then combining the date with the payment ID to have a unique key that we can use to look up the name.
{=MAX(($A$3:$A$8 = A12) * (B12 >= $B$3:$B$8) * (B12 <= $C$3:$C$8) * $B$3:$B$8) & A12}
And lastly we can perform an Index match, looking up the output of the above formula in the concatenated range of date and payment ID in the promises table
{=INDEX(
$D$3:$D$8,
MATCH(
MAX(($A$3:$A$8 = A14) * (B14 >= $B$3:$B$8) * (B14 <= $C$3:$C$8) * $B$3:$B$8) & A14,
$B$3:$B$8 & $A$3:$A$8,
0))}
The {} means you have to enter the formula using Ctrl + Shift + Enter
Note that this will be a lot more readable and intuitive if you name the ranges.

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

array formula: sum to date

I have a number of invoices:
invoice #
start
end
paid on
amount
paid to date (hardcoded)
1
01/01/2020
30/01/2020
01/02/2020
£10.00
£10.10
2
01/02/2020
20/02/2020
01/03/2020
£7.50
£17.60
3
21/02/2020
30/02/2020
01/03/2020
£2.50
£20.10
4
01/01/2000
30/01/2000
01/03/2000
£0.10
£0.10
Where the invoices
are not necessarily sorted by start and end date
are not necessarily sorted by paid date.
might not have a paid-on value.
I want to add a field called paid to date that would show me the amount I have been paid so far where it would add the amount for:
the current invoice
the invoices that were paid prior to this invoice's paid-on date.
the invoices with the same paid-on date as this invoice but with a start date <= this invoice's start date.
Effectively mirroring the hard-coded column.
This is how I do it with a query (which might not be the simplest/most elegant way of doing it)
=Index(
query(
A1:E10,
"select SUM(E)
where D is not null
and (
D < date '"& TEXT( D2,"yyyy-mm-dd")&"'
OR (
D = date '"& TEXT( D2,"yyyy-mm-dd")&"'
and
B <= date '"& TEXT( B2,"yyyy-mm-dd")&"'
)
)"
),
2, 1
)
which is all well and good. but I want to be able to do it with array-formula, so I can have it auto-generated for me.
I tried using it inside array-formula but the value is only ever generated for the first row. I guess it's misinterpreting the range I am passing as the range of the query function, ie A1:E10. is there an easy way of fixing it?
Do I need to use VLookup?
Here is a sample spreadsheet.
try:
=INDEX(IFNA(VLOOKUP(A2:A, {INDEX(SORT({A2:B, D2:E}, 2, 1, 3, 1),,1),
MMULT(TRANSPOSE((ROW(E2:E)<=TRANSPOSE(ROW(E2:E)))*
INDEX(SORT({A2:B, D2:E}, 2, 1, 3, 1),,4)), SIGN(E2:E))}, 2, 0)))
If you have Excel 365, you can Filter directly.
Note that I am using a table with structured references. Then you don't need to adjust the range references as you add/remove rows from the table.
=SUM(FILTER([amount],([paid on]<[#[paid on]])+(([paid on]=[#[paid on]])*([start]<[#start])),0),[#amount])
This part does the filtering:
...([paid on]<[#[paid on]])+(([paid on]=[#[paid on]])*([start]<[#start]))...
Note: You can use the same algorithm in Sheets:
Note that I am using regular addressing, and also using a semicolon instead of a comma for the argument separators
=sum(iferror(FILTER($E$2:$E$5;($D$2:$D$5<$D2)+(($D$2:$D$5=$D2)*($B$2:$B$5<$B2)));0);E2)

Formula in saved search

I have created a saved search that in the criteria I have all the bank accounts with multiple currencies, in the results I have a column that calculate the amount (account currency) using this formula:
CASE WHEN {account.number} IN ('10003','10005','10007','10008','10009','10010','10011','10012','10013','10101','10102','10103','10104','10105','10106') THEN {amount} ELSE {fxamount} END
I need to add another column that calculate the accumulated balance for each day , according to the account currency, the same way it appears in the trail balance netsuite report.
for example if the first transaction on 01/01/2021 in BANK USD is 100 so I want the value in the new column will be 100, if on 02/01/2021 I have payment of -45 USD then I want the value will be 55 (100-45) etc...
I hope its clear enough, please advise !
Nir
If I understand your question, you want a running total?
Perhaps this will work for you, in a currency formula use:
SUM/* comment */(CASE WHEN {account.number} IN ('10003','10005','10007','10008','10009','10010','10011','10012','10013','10101','10102','10103','10104','10105','10106') THEN {amount} ELSE {fxamount} END) OVER(PARTITION BY {account.number} ORDER BY {internalid} ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
I found this solution from this blog:
https://blog.prolecto.com/2015/05/26/solving-the-netsuite-cumulative-saved-search-tally-challenge/
I apologize if I misunderstood the question.

Sumifs with date difference in range

I have a spreadsheet with:
list of recurrent expenses
other lists of recurring stuff, not important
an estimation of inflow and outflow monthly
The estimation is calculated with the following criteria (in AND logic):
date is between "since" and "to" (if since is empty, it is always valid, and the same for "to")
the month is a multiple of "every month" starting from "since", i.e. the voice must be included if "data" = "since" + "every months" * x, where x is an integer number
I wanted to create a sumifs like the following (Italian Excel, sorry):
=SOMMA.PIÙ.SE('Uscite'!$E$2:$E$1048576;'Uscite'!$C$2:$C$1048576;"<="&'v3'!$A2;'Uscite'!$D$2:$D$1048576;">="&'v3'!$A2;?????)
where ????? is the missing piece: I considered using a DATEDIF with "m", in order to get the difference in months between cell Ax and 'Uscite'!Since, then verifying if this difference is a perfect multiple of "every months", but no clue how to do it.
Any suggestion?
Thanks for your time!
In english formulation, you could do:
=SUM( 'Entrate ricorrenti'!$E$2:$E$100 *
( ('Entrate ricorrenti'!$D$2:$D$100 >= 'v3'!A2) + ISBLANK('Entrate ricorrenti'!$D$2:$D$100) ) *
IFERROR( MOD( DATEDIF( 'Entrate ricorrenti'!$C$2:$C$100, 'v3'!A2, "M" ), 'Entrate ricorrenti'!$B$2:$B$100 ) = 0,
0 ) )
In Italian:
=SOMMA( 'Entrate ricorrenti'!$E$2:$E$100 *
( ('Entrate ricorrenti'!$D$2:$D$100 >= 'v3'!A2) + VAL.VUOTO('Entrate ricorrenti'!$D$2:$D$100) ) *
SE.ERRORE( RESTO( DATA.DIFF( 'Entrate ricorrenti'!$C$2:$C$100; 'v3'!A2; "M" ); 'Entrate ricorrenti'!$B$2:$B$100 ) = 0;
0 ) )
So, this uses the very nice dinosaur function that you taught me about today. I have never seen this except for DAX.
It simply filters out the payments that stopped before the target date, ('v3'!A2) by multiplying the payment values, ('Entrate ricorrenti'!$E$2:$E$100), times the boolean expression
(('Entrate ricorrenti'!$D$2:$D$100 >= 'v3'!A2) + ISBLANK('Entrate ricorrenti'!$D$2:$D$100))
that also checks to see if the To Date is blank. Then it multiplies that times the modulo of the DATEDIF in months by the Frequency in months. If that is zero, then a payment lands in that month. DATEDIF has the nice property that if the date difference is negative, it generates an N/A error. This allows us to wrap it in an IFERROR to replace that with zero - this prevents the formula from including payments that have not yet started.

Trying to sum where multiple instances of an account number in a month

I have a data sheet that col A is an account number, col F is a payment amount, col I is a user, and col H is a payment date....I am trying to sum payment amounts that fall in the same month for a particular user for a average monthly payment amount. It is a list of future payments that can have weekly or biweekly payments. I am trying to find which payments fall within the same month and sum those amounts and then average those payment amounts??? Any clues? This formula gets me a unique value for each user but cannot seem to get what I am looking for:
=SUM(--(FREQUENCY(IF('RD-CRC Payments'!I:I <> " ",IF('RD-CRC Payments'!I:I=C5,'RD-CRC Payments'!A:A)),'RD-CRC Payments'!A:A)>0))
This maybe what you are looking for. Enter cell with Name and cell with Date/Month you want to search for where it says CELLWITHDATE and CELLWITHNAME.
This will get you the sum.
=SUMIFS('RD-CRC Payments'!F:F,'RD-CRC Payments'!H:H,">="&EOMONTH(CELLWITHDATE,-1)+1,'RD-CRC Payments'!H:H,"<="&EOMONTH(CELLWITHDATE,0),'RD-CRC Payments'!I:I,CELLWITHNAME)
This will get you the average payment for that month.
=SUMIFS('RD-CRC Payments'!F:F,'RD-CRC Payments'!H:H,">="&EOMONTH(CELLWITHDATE,-1)+1,'RD-CRC Payments'!H:H,"<="&EOMONTH(CELLWITHDATE,0),'RD-CRC Payments'!I:I,CELLWITHNAME)/COUNTIFS('RD-CRC Payments'!H:H,">="&EOMONTH(CELLWITHDATE,-1)+1,'RD-CRC Payments'!H:H,"<="&EOMONTH(CELLWITHDATE,0),'RD-CRC Payments'!I:I,CELLWITHNAME)
I decided to add this if you need to use a Month instead of an Actual Date. This can be adjusted to use over years as well.
=SUMIFS($F:$F,$H:$H,">="&DATEVALUE(CellWithMonth&" 1"),$H:$H,"<="&EOMONTH(DATEVALUE(CellWithMonth&" 1"),0),$I:$I,CellWithName)
=SUMIFS($F:$F,$H:$H,">="&EOMONTH(DATEVALUE(CellWithMonth&" 1"),-1)+1,$H:$H,"<="&EOMONTH(DATEVALUE(CellWithMonth&" 1"),0),$I:$I,CellWithName)/COUNTIFS($H:$H,">="&EOMONTH(DATEVALUE(CellWithMonth&" 1"),-1)+1,$H:$H,"<="&EOMONTH(DATEVALUE(CellWithMonth&" 1"),0),$I:$I,CellWithName)

Resources