Qlikview Count of ids in last 12 months in text object (box) - count

I have two fields in my table Date & ID, i want to put in a text box the count of all the ids for the last 12 months.
This returns nothing:
=Num(count({$<DATE={'>=$(=AddMonths(Today(),-12))'}>}[ID]),'#,##0')
This returns the correct count:
=count(ID)
This returns the total for the year (2015):
SUM(IF( year(DATE) = year(today()),1,0))

Using the MonthName function on the date to parse it exactly as the AddMonths function does
=SUM(IF( (date(Monthname(DATE),'MMM-YY')) >=(AddMonths(Today(),-12)),1,0))

Related

Apache Drill: Group by week

I tried to group my daily data by week (given a reference date) to generate a smaller panel data set.
I used postgres before and there it was quite easy:
CREATE TABLE videos_weekly AS SELECT channel_id,
CEIL(DATE_PART('day', observation_date - '2016-02-10')/7) AS week
FROM videos GROUP BY channel_id, week;
But it seems like it is not possible to subtract a timestamp with a date string in Drill. I found the AGE function, which returns an interval between two dates, but how to convert this into an integer (number of days or weeks)?
DATE_SUB may help you here. Following is an example:
SELECT extract(day from date_sub('2016-11-13', cast('2015-01-01' as timestamp)))/7 FROM (VALUES(1));
This will return number of weeks between 2015-01-01 and 2016-11-13.
Click here for documentation

How do you update an existing date to a random date in a range?

In one of my tables I have datetime field in which the data in the table column is populated with something like "2016-01-07 01:33:00".
What I want to do is change ONLY the date to a random date within a range (ie: 2016-02-01 thru 2016-02-28) without changing the time. The end result might be "2016-02-13 01:33:00".
What mysql command string would accomplish this task?
Something like
UPDATE someTable SET someDate = DATE_ADD(
someDate,
INTERVAL
DATEDIFF(rangeStart, someDate) +
ROUND(RAND()*DATEDIFF(rangeEnd, rangeStart))
DAY
);
where someTable.someDate is your existing data, and rangeStart and rangeEnd are the boundaries of your target date range.
Here you take the initial date, add enough days to it to reach the range start, and then further add a random number of days no greater than the number of days in your target range.
In MsSQL it could be:
select dateadd(day,cast((RAND() * 30) as int),getdate())
Substitute getdate() with your input date.
(RAND() * 30) is used to randomly generate a number of days up to 30.

Get RowCount With Date Comparasion in SSRS

I am new to SSRS.
I have a dataset, my dataset brings data from a stored procedure.
one of the parameters of my sp is StartDate and another one is EndDate. Their type is datetime
And the table has a dateTime Column called Date.
I have two gauges and I wanna bind integer values to my gauges.
First one is the count of rows where Date < DateAdd(DateInterval.Hour,24,StartDate)
and te second is count of rows where Date > DateAdd(DateInterval.Hour,24,StartDate)
How will I write the exact script. Whatever I wrote is not working.
I appreciate any help, thanks.
You need to set the gauge Pointer value as something like:
=Sum(IIf(DateDiff(DateInterval.Day, Parameters!StartDate.Value, Fields!Date.Value) >= 1
, 1
, 0))
This is counting rows where the time difference is less than a day compared to the parameter StartDate. Just change it slightly to get those where the difference is at least a day:
=Sum(IIf(DateDiff(DateInterval.Day, Parameters!StartDate.Value, Fields!Date.Value) >= 1
, 0
, 1))
Worked fine for me in a quick test:

Error in repeating table sum in InfoPath

I'm using InfoPath 2003 to produce a form which includes a repeating table of records that include a date field (StartDate) and a value field (TotalElapsed). I have date pickers for start and end dates on the form (beginDate and endDate), and there is a text box after the table which I want to have show the total sum of the integer field for records that have a date between the start and end date selections. The text box value parameter generated when I use the 'Insert Field or Group...' and 'Filter Data...' options, is below:
sum(#TotalElapsed[msxsl:string-compare(#StartDate, beginDate) >= 0 and msxsl:string-compare(#StartDate, endDate) <= 0])
This gives almost the correct sum calculation, with the exception that any records with a date that matches the end date are not included in the sum. Any records with dates from (and including) the start date, up to the day before the end date, are all included in the sum. Any ideas why the end date records aren't included in the sum?
Thanks
The above equation works fine. To use the >= and <= the Start Date should be in type of Date.
sum(Total[msxsl:string-compare(StartDate, BeginDate) >= 0 and msxsl:string-compare(StartDate, EndDate) <= 0])

Change database value based on date (ASP)

I have 3 dropdown lists in a form for the user to input the date by day, month and year. How can I make that once t is the date that been input by the user, it will change the status from PUBLISH to UNPUBLISHED in the database?
Below is my codes:
Need your help. Thanks.
Why don't you use the DateSerial function to convert the separate values into date values, and use that to compare two dates.
From the page at W3Schools:
The DateSerial function returns a Variant of subtype Date for a specified year, month, and day.
Syntax
DateSerial(year,month,day)
Parameter Description
year Required. A number between 100 and 9999, or a numeric expression. Values between 0 and 99 are interpreted as the years 1900–1999. For all other year arguments, use a complete four-digit year
month Required. Any numeric expression
day Required. Any numeric expression
Examples
Example 1
document.write(DateSerial(2010,2,3))
The output of the code above will be:
2/3/2010
Example 2
Subtract 10 days:
document.write(DateSerial(2010,2,3-10))
The output of the code above will be:
1/24/2010

Resources