I have controller that is using a standardSetController to implement pagination. I want to filter by the trade date for the last 13 months. The date literals don't have a filter by Last_N_Months:N
Is there a way I can filter by the last 13 months?
Here is my current query:
setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([select TransactionType__c, TradeDate__c, ShareClass__c,
SettlementDate__c, Name, Fund__r.Name, Fund__r.Id, FirstTransaction__c, DCPosition__c, DBR__r.Name, DBR__r.Id, DBR__c,
Amount__c from Transaction__c where DBRPrimaryContact__r.Contact__c =: con.Id ORDER BY TradeDate__c ASC]));
If I can't filter by 13 months, what is the total number of records that can be returned in a query? Is it 2000? There can be a significant number of records for this object and I want to limit the results by 13 months of data. Once I have that result set, I want to add filtering by options.
Thanks for any help.
Try the code below for filtering Date range - you can programatically calculate exact date ranges
DATE d1 = date.today();
Date d2 = d1.addMonths(-13);
Integer d3 = d2.daysBetween(d1);
System.debug('*************' + [SELECT Id FROM Account WHERE CreatedDate >= :d2 AND CreatedDate <=:d1]);
For filtering by date you have LAST_90_DAYS or LAST_N_DAYS:90 like this
SELECT Id FROM Account WHERE CreatedDate = LAST_N_DAYS:90
More info in this link
And yes the total number retrieved in one query is 2000
Related
I have 2 tables on orders with the order validity date and in transit stock (stock reaching where the order will be serviced).
(using sample data to simplify for understanding)
I am looking for a final calculation like this in my final table -
have done the calculation till column 4 in power BI
if this was in excel i could have simply done
used_stock(2) = serviced(1) + used_stock(1)
avail_stock(2) = total_qty(2) - used_stock(2)
serviced(2) = min(order(2),avail_stock(2))
My base tables look like this -
order table -
intransit table -
I have done the total_qty measure calculation by finding the cumulative sum of shipment quantity for the dates before selected value of order validity date.
I am trying to do the rest of the measures but ending up in circular references. Is there a way I can do it?
edit -
Clarifying it a bit more for the logic needed -
let's say the 2nd order is 15 and the 2nd shipment reaches on 24th, then the base data and output table should look like this -
With present proposed solution the table will erroneously look like -
Try with these below measures-
total_qty =
VAR current_row_date = MIN('order'[order valid till date])
RETURN
CALCULATE(
SUM(intrasit[quantity in shipment]),
FILTER(
ALL(intrasit),
intrasit[expected date of reaching] < current_row_date
)
)
used_stock =
VAR current_row_date = MIN('order'[order valid till date])
RETURN
CALCULATE(
SUM('order'[order quantity]),
FILTER(
ALL('order'),
'order'[order valid till date] < current_row_date
)
) + 0
avail_stock = [total_qty] - [used_stock]
serviced =
IF(
MIN('order'[order quantity]) <= [avail_stock],
MIN('order'[order quantity]),
[avail_stock]
)
Here is your final output-
I have tried 2 codes, the first one hasn't worked, while the second has. I basically have to display how many games were played on Mondays and show the teams that played them.
MATCH (t:Teams)
WHERE date({year:2019, month: 1 }) > t.Date <= date({year:2018, month:12})
RETURN t.HomeTeam AS HomeTeam,
t.AwayTeam AS AwayTeam,
t.Date AS Date
The result is: (No changes, no records) - nothing
MATCH (t:Teams)
WITH [item in split(t.Date, "/") | toInteger(item)] AS dateComponents
WITH ({day: dateComponents[0], month: dateComponents[1], year: dateComponents[2]}).dayOfWeek AS date
WHERE date = 1
RETURN COUNT(*)
The result is: Count(*) 0
I think there may be a couple of things going on in your first query. The date matching line
WHERE date({year:2019, month: 1 }) > t.Date <= date({year:2018, month:12})
is looking for a date that is less than 20190101 and less than or equal to 20181201. If you are actually looking for a date between those two values you need to change the operator to greather than equals for 201801.
That said, if Date is actually a string then the date comparison will not work either.
In your second query, it looks like you decided that Date was indeed a string and you split it up but still did not get any results. Although you break the date string up into its components you did not supply the date() function around your date components in this line...
WITH ({day: dateComponents[0], month: dateComponents[1], year: dateComponents[2]}).dayOfWeek AS date
Try this for your second query.
MATCH (t:Teams)
WITH [item in split(t.Date, "/") | toInteger(item)] AS dateComponents
WITH date({day: dateComponents[0], month: dateComponents[1], year: dateComponents[2]}).dayOfWeek AS date
WHERE date = 1
RETURN COUNT(*)
My objective is to count Lead records based on simple date range query in local time
Integer TotalLeads = [ Select Count() From Lead where createddate >= fromdate CreatedDate <= todate];
Fairly basic. However, the issue I'm running into is I only want to count the leads for the "local" time not UTC; createddate is in UTC for lead records.
Sample dates:
From: 03/23/2017
To: 03/29/2017
For these sample dates and my local time is UTC - 7 (Los Angeles), so my query would be
Integer TotalLeads = [ Select Count() From Lead where createddate >= 2017-03-23T07:00:00z AND CreatedDate <= 2017-03-30T06:59:59z];
If these are my dates, how do I append the local time so from date is 2017-03-23T07:00:00z and to date is 2017-03-30T06:59:59z?
Using from date first, I was able to do the following but can't figure how to keep it in local time
// Date
date ds = date.valueof('2017-03-23');
string dm = string.valueOf( ds.month());
string dd = string.valueOf(ds.day());
string dy = string.valueOf(ds.year());
// DateTime Midnight (UTC)
String SDate = string.valueof(dm +'/' + dd + '/' + dy + ' 12:00 AM');
system.debug(SDate); // -> 3/23/2017 12:00 AM
// DateTime (Local Time)
datetime ds2 = datetime.parse(SDate );
system.debug(ds2); // -> 2017-03-23 07:00:00
system.debug(ds2.format('yyyy-MM-dd\'T\'hh:mm:ss'')); // -> 2017-03-23T12:00:00
As you can see, using ds2.format put its in the format I need but back to UTC (midnight), I need it to be 2017-03-23T07:00:00
Any suggestions?
Thanks!
Figured what I was doing wrong. The date calculation was fine, it had to do with how this was being passed to a batch job.
I want to pull today's date plus the last four weeks. Does anyone know a function for this in Netezza? What I have below is a guess that doesn't work. Also, I don't want to extract the date.
Select c.BUSINESS_UNIT_NBR, c.BUSINESS_UNIT_NAME, b.STORE_NBR, b.INV_CUST_ACNT_NBR,c.INV_CUST_NAME, a.NDC_NBR, a.GENERIC_NAME, a.INV_NBR, a.CONTRACT_ID, a.CONTRACT_NAME, a.ORD_DT, b.INV_DT, b.SHIP_DT, a.ORD_QTY, a.SHIPPED_QTY, a.INV_PRICE_AMT, a.INV_COST_AMT, a.MARKUP_MARKDOWN_PCT, a.INV_LINE_AMT
from fct_dly_invoice_detail a, fct_dly_invoice_header b, dim_invoice_customer c
where a.INV_HDR_SK = b.INV_HDR_SK
and b.DIM_INV_CUST_SK = c.DIM_INV_CUST_SK
and a.SRC_SYS_CD = 'ABC'
and a.NDC_NBR is not null
**and b.inv_dt(current_date)-16**
and b.store_nbr in (813, 1197, 2771, 3048, 3177, 3387, 3477, 3602, 3766, 3912, 4020, 4138, 4228, 4434, 4435, 4507, 4742, 4791, 5353, 5392, 5775, 5776, 5890, 6177, 6692, 6736, 6806, 7933, 9175, 9472)
Assuming inv_dt is the column you want to filter on, your where predicate should include:
WHERE
...
inv_dt between CURRENT_DATE - 16 and CURRENT_DATE
...
16 days does not equal four weeks, but adjust that number accordingly to your needs.
i have 2 custom objects appointment_c and TimeDrive_c.
Appointment has fields
startdate__c
contact__c
TimeDrive__c has
Target_date__c
contact__c
CreatedDate
Here is what i need to do
I need to get all get all records with in a specific date range
select id, Target_date__c, Contact__c, Name, CreatedDate
from TimeDrive__c where Target_date__c >=:startdate and
Target_date__c <=:enddate
i need to loop through each record in this list and check if there are appointments for this contact which has startdate fall between targetdate and createddate
Here is the bit i have done till now
timeDriverLst = [select id, Target_date__c, Contact__c, Name, CreatedDate
from TimeDrive__c where Target_date__c >=:startdate and
Target_date__c <=:enddate ];
if(timeDriverLst.size() >0){
for(integer i =0; i < timeDriverLst.size(); i++)
{
mapTime.put(timeDriverLst[i].id, timeDriverLst[i]);
/* appLst = [Select Name, Contact__c from Appointment__c where (StartDate__c > = :timeDriverLst[i].CreatedDate
and StartDateTime__c <=:timeDriverLst[i].Target_date__c) and Contact__c = :timeDriverLst[i].Contact__c ];
*/
}
I know i shouldnt have a SOQL query within a for loop. How can i avoid this and achieve the requirement.
An ugly, but possibly usable solution: You could get all the contact ids from the time driver list and also find the earliest created date. Then you could pull out all the appointments whose contact id is in the contact id list and whose date is between the earliest created date and the target date. Then you would need to do a double loop, checking each appointment against each time driver. (Ordering the appts by contact or by date as you retrieve them might help here).