SPARQL search for first binding then stop - sparql

I have some stock data and I want to find the stock closing price two days following an event in which ?date was bound:
BIND (?date + \"P2D\"^^xsd:dayTimeDuration As ?doe)
?event <http://www.foo.com/stock/date> ?doe.
?event <http://www.foo.com/stock/close> ?close.
I can think of ways to increment the 2 but I want to stop as soon as I get a value for ?close. I want to increment "trading days" not really calendar days.
Is there an elegant way to keep incrementing "P2D" but then stop when I get a value?

I'd do something like SELECT the closing values for every day in the week (or whatever the longest gap in trading is) starting 2 calendar days after ?doe, then ORDER BY date, and LIMIT 1.
Elegant? Maybe not. But no stepping, and should be fairly fast.

Related

sql last day date function

I have table like below, and I need to choose only the data for end day of each month. What proper query should I use ? I need also automated it, and with each subsequent montt the last day each month needs to be choose automaticly.
date_list
date=20201231
date=20211220
date=20201130
date=20201115
date=20201030
date=20201009
.
.
.
.
thanks,

date during your collection period saw the greatest number of matching tweets

hello i want to write a query which tells me the great number of tweets collect on a particular day like my question is
"date during your collection period saw the greatest number of matching tweets"
i have collected data from tweetcatcher but didnt know which query i use
Not much to go on, but based on your comment
SELECT date, Tweets=count(*) FROM Course GROUP BY date Order by 2 Desc
You could also add Select Top 1 ... if you want only one record.

Creating a DAX pattern that counts days between a date field and a month value on a chart's x-axis

I am struggling with a DAX pattern to allow me to plot an average duration value on a chart.
Here is the problem: My dataset has a field called dtOpened which is a date value describing when something started, and I want to be able to calculate the duration in days since that date.
I then want to be able to create an average duration since that date over a time period.
It is very easy to do when thinking about the value as it is now, but I want to be able to show a chart that describes what that average value would have been over various time periods on the x-axis (month/quarter/year).
The problem that I am facing is that if I create a calculated column to find the current age (NOW() - [dtOpened]), then it always uses the NOW() function - which is no use for historic time spans. Maybe I need a Measure for this, rather than a calculated column, but I cannot work out how to do it.
I have thought about using LASTDATE (rather than NOW) to work out what the last date would be in the filter context of any single month/quarter/year, but if the current month is only half way through, then it would probably need to consider today's date as the value from which to subtract the dtOpened value.
I would appreciate any help or pointers that you can give me!
It looks like you have a table (let's call it Cases) storing your cases with one record per case with fields like the following:
casename, dtOpened, OpenClosedFlag
You should create a date table with on record per day spanning your date range. The date table will have a month ending date field identifying the last day of the month (same for quarter & year). But this will be a disconnected date table. Don't create a relationship between the Date on the Date table and your case open date.
Then use iterative averagex to average the date differences.
Average Duration (days) :=
CALCULATE (
AVERAGEX ( Cases, MAX ( DateTable[Month Ending] ) - Cases[dtopened] ),
FILTER ( Cases, Cases[OpenClosedFlag] = "Open" ),
FILTER ( Cases, Cases[dtopened] <= MAX ( DateTable[Month Ending] ) )
)
Once you plot the measure against your Month you should see the average values represented correctly. You can do something similar for quarter & year.
You're a genius, Rory; Thanks.
In my example, I had a dtClosed field rather than an Opened/Closed flag, so there was one extra piece of filtering to do to test if the Case was closed at that point in time. So my measure ended up looking like this:
Average Duration:=CALCULATE(
AVERAGEX(CasesOnly, MAX(DT[LastDateM]) - CasesOnly[Owner Opened dtOnly]),
FILTER(CasesOnly, OR(ISBLANK(CasesOnly[Owner Resolution dtOnly]),
CasesOnly[Owner Resolution dtOnly] > MAX(DT[LastDateM]))),
FILTER(CasesOnly, CasesOnly[Owner Opened dtOnly] <= MAX(DT[LastDateM]))
)
And to get the chart, I plotted the DT[Date] field on the x-axis.
Thanks very much again.

Need NetSuite search formula to display employee time records by projects (in rows) and day of week (in columns)

I'm trying to create a NetSuite Time search that emulates the chart style display on an employee's weekly time record, with projects listed in rows and days of the week listed in columns, with totals by day and by project. The goal is to have a search auto filtered by "Last Week" that can be used with a drop down selector filter for employees. I know there are better ways, but this is a very specific demand from someone above who believes the NS time record is a "query" and wants it to act like one.
I'm good with NS searches but know almost next to nothing about coding. I tried some basic sum formulas using CASE WHEN but am having 2 issues:
1) Can't figure out how to get CASE WHEN to sort by the weekday output from DAY of the {date} and subsequently total the hours.
2) Not sure how to total hh:mm formatted time in searches, and can't figure out what the system name of the "Duration (Decimal)" field is.
Just need one line of a sum formula to total time data from one day of the week, and a way to solve the hh:mm issue and I am good to go from there.
CASE WHEN to_char({date}, 'D') LIKE 1 THEN {durationdecimal} ELSE 0 END
SUN = 1, MON = 2, etc.

How can I get the average of a date field?

I want to get the average of days between some dates, for example, I have a table called Patient that has the id of the registration, patient's id, entry date and final date:
(1,1,'07-04-2014','08-04-2014'),
(2,2,'07-04-2014','07-04-2014'),
(3,3,'08-04-2014','10-04-2014'),
(4,4,'09-04-2014','10-04-2014')
I want to get the average of days of the entry fields, I have tried a lot of thing but I only get random results. I tried with dtiff but it needs two arguments and I only need one.
You could get the average DURATION between a fixed date and the date field. But averaging a date doesn't really make sense.
SELECT AVG(DATEDIFF(DD,'19700101',dateField)) AS avgDays
You could say the "average" date would then be: DATEADD(DD,avgDays,'19700101')
But I'm not sure if that makes sense in the context of what you're trying to do.
thanks for answering, maybe I couldn't express what I wanted to do but I found a solution and it was actually vey simple:
select Patient.Name, avg(day(Patient.FinalDate) - day(Patient.EntryDate)) as [Average] from Patient,DetailPatient where Patient.IdPatient=DetailPatient.IdPatiene group by DetailPatient.Name
I know it looks very simple haha, but is the first time I use avg function this way.
Thank you guys.