find if data existed 6 months ago ssrs - reporting-services

In SSRS report builder I am trying to write an expression for calculated fields in my dataset to see if this data exists now, existed 6 months ago, and existed a year ago. (So 3 different calculated fields).
I don't want to use different datasets as the information all needs to go into a table with a percentage change column.
I have the from and to dates of the data and have been trying to write something along the lines of
=IIF(Fields!From.Value<-6months AND Fields!To.Value>-6months, true, false)
I'm obviously missing something in my expression but my knowledge in this is limited. Any ideas on how to get this to do what I want it to?
my data basically is this (but being pulled from various tables in our database)
person ID - condition 1 - from date - to date
person ID - condition 2 - from date - to date
person ID - condition 1 - from date - to date
person ID - condition 3 - from date - to date
etc.
I've been asked to make a table with the conditions as the rows, the columns are "exists now", "existed 6 months ago" and "existed 12 months ago" and a count of the person IDs as the data
the from and to fields are date fields

The visibility thing can be a little confusing sometimes, as with everything in SSRS it can be finicky.
Since you're new at this I would recommend something easy like trying to hide your first row. You'll probably want to do this by right clicking the table and going to properties. Under visibility, you can add an expression. Try hiding a row by the unique ID or something like that first...
=IIF(Fields!UID.Value=1234, TRUE, FALSE)
The reason I say to go through this is to make sure you're able to properly hide a row. If you are using the visibility in groups instead, sometimes it doesn't work expected. Anyway, once you get that working, you'll want to do something like this.
=IIF( (DateDiff("m", CDate(Fields!FromDate.Value), Now()) < 5 AND DateDiff("m", CDate(Fields!ToDate.Value), Now()) > 5), FALSE, TRUE)
You'll be using the DateDiff function to calculate the difference between the date and NOW() (which returns current date). The "m" specifies you want to know how many months between dates. CDate will cast your field into a DateTime object.

Related

Access Database - moving months in column header to rows with the corresponding amount

I'm sure this is rather simple, but I can't figure it out. Working in Access - Budget amounts are entered by month with the month in the column header. The preceding columns include Account#, CostCenter, BudgetCategory and an optional ID field. I'm trying to transpose the data to bring the months into a row along with the corresponding amount.
Image1: Input format
Image2: Desired output
Create a table that contains a single column with 12 records with values of 1-12. These represent the months. Maybe name the field "Mo". I don't like naming it "Month" in Access as this is also a built-in function name.
Create a query with your budget table and the new 12-month table. Don't create a join (no line). If you run now, you'll get 12 times the number of records in your budget table. This is what you want.
For your new amount field, you'll have a formula like below:
Amount: iif(Mo=1,Jan,iif(Mo=2,Feb,iif(Mo=3,Mar,Apr)))
I just put in 4 months above, but you can expand to 12 months.
If you have space if field names, put brackets around field names in your formula like:
Amount: iif([Mo num]=1,[Jan Budget], ...

CURDATE functionality from db2 query

I'm trying to apply 'curdate()' functionality to a select statement from DB2. I'm used to MySQL but I'm still trying to get the hang of a lot of the DB2 functionality and how to essentially marry the two.
My query is complete except for one line. I'm trying to select based on a ship date, which is the column EXTD1H and I need to check it against today or curdate(). The problem is that column in DB2 is an integer format, not a date format, and I don't have the option of changing it. In prior inserts to mysql, I've been able to put it into Y-m-d format and I know I can trim the year using LEFT(EXTD1H, 4) but I have no idea how to modify my select so that I can say WHERE EXTD1H is today so that I'm only selecting records for this date.
Here's the query:
select
invnoz as ORDER,
fstatz as STATUS
from gportafl
/*where EXTD1H is curdate, hypothetically*/
AND FSTATZ <> 'S'
limit 20;
As you can see, I have a commented line where my issue is. I'm sure it's simple I just can't seem to find in the documentation exactly what I'm looking for, which is to be able to use that INT column to verify that selected records are from today.
UPDATE:
All values from the column are in YYYYMMDD format i.e.
20180202
but it should be 2018-02-02
It's best not to do operations on the columns, so the indexes are used.
You can typecast the current date to fit your data as follows:
WHERE extd1h = INTEGER(VARCHAR_FORMAT(CURRENT DATE,'YYYYMMDD'))

Updating mysql table whilst shifting values

I have a table that I use for statistical purposes.
Its columns are id and 1,2,3,..,31 and pivot.
This table gives the number of views on each day for the last 31 days.
1 gives the number of views for yesterday.
14 gives the number of views for 14 days ago.
etc ...
(pivot is just used to calculate the number of views)
I would use a cron job every day to update this table, but how would I go about "shifting" all the values to the side ( value column 15 would become value column 16; new value for column 1; delete value for column 31)
Define a table with only two columns — "date" and "views"
INSERT a new row in the table with the view count for that day when the CRON job runs
Modify your application query to read through this new table over a custom date range, which could be 31 days or anything else either — please have a look at this link to get an idea:
MySQL Query - Records between Today and Last 30 Days
Not really sure how pivot is being used here. However, I'm almost certain that if you're using it to store the sum of the views, it could as well be computed by using SUM() or GROUP BY without having to need a separate column in the table
As far as data archival / removal is concerned, your daily CRON job could be modified to include a DELETE query (as the last step) which cleans up records older than a certain date. Again, you could use the link above to get your "target" date
.
I apologise that this might sound like a little too long a solution to what you've asked for. However, I feel, this approach should help you organise and maintain the table in question in a better way.

How to create a Multiple date picker for a search form

I am quite a newbie to MS Access.I am working with a search form in MS Access and I want to create a date picker in which I can select multiple dates which will be an input for a Query that is used to search and display the results from my table for the records that have the selected dates. I did some research on this,however I was unable to find out a feasible solution for my problem.
As I see there are only 2 ways in which this can be done.The first way is that is using two date pickers one for from date and other for to date and then search for the records between these days which is not very feasible for my scenario as I might want to choose two different dates for example 4th of Jan and 6th of Jan and display results for only those days.
The other method is to use a list box which displays all the dates that are present in the database and choose from that however this is not going to work for me as if I have a very long list of dates such as from 1st Jan to 31st Jan then it would be very time consuming and also I might select a date which I do not want to to search for also in the results.
Could anybody suggest me how can I solve this problem.I am looking for a multiple date picker property in access.Is it possible to achieve this through the form properties? If yes how can it be done? Or is there any other solution for this problem?
Thanks in Advance.
I would recommend creating a temp table consisting of two fields, a Yes/No field and a Date field. Populate the date field (don't name it 'date') with all of the dates from your list of dates. Then on your search form add a subform bound to the temp table. Users would simply check the box next to the desired dates. Then modify your query to include the temp table with a join on the date fields and criteria that the Yes/No field is True (Yes).
Its doubtful youre still looking for this but for anyone else that happens accross this topic I modified an existing datepicker to allow selection of any number of non-contiguous dates, and insert them to a table. I posted it on UtterAccess (A great forum for Access questions). A link to the forum topic is below, but you need to create an account to download the example file.
http://www.utteraccess.com/forum/index.php?showtopic=1738361&st=0#entry2535392
You could combine the two approaches and have
Two textboxes to filter for a short date range (say 1 month dates)
Show the dates in this date range in a multiselect listbox where the user can select the specific dates they need.

query to aggregat data by day to generate charts - rows unkown

I started building a search engine monitor. I'm pulling data from the google rest api into a mysql database with the following fields: date, search-keyword, domain, url, position.
Now I got into trouble querying and outputting the data for charting. The results go up and down, new results from google come into the list which haven't been there on the first day. However for charting I have to assign the first days at least blank values to output a chart.
What I do right now: First I select every domain showing up in the period. Lets say the for the keyword searchengine I get the domains wikipedia.org, ixquick.com, yahoo.com, searchenginewatch.com When I make another request for ever domain to query an array of rankings grouped by day. leading to the ...
Problem: Is where any query (mysql/nosql) which returns for each day an average and if where is no row a default value e.g. blank?
Result should look like:
dates={01/01/2014,02,03,04,05,06,07,08,...,31}
wikipedie={1,1,1,1,1,1,1,1,...,1}
yahoo = {"","",7,5,3,3,3,...,3}
You can create a date table, select the date range you'd like, and outer join your data to it, filling in 0s for values that do not exist for a given term/date.
Edit:
Some more details.
1) Create a table that has a row for every date +- 10 years (or whatever is appropriate). You can make this one column if you'd like, or many columns (date, month, year, etc.). The second approach makes this extensible if you want to summarize by various rollups in the future.
2) Outer join your table to the date table and use a NVL statement to coerce any null averages to 0.
3) Profit!
If your results are grouped by date, how can MySQL know there's (for example) 31 days in that month?
On the other hand, you can somehow fill the holes in PHP by loop through the array and fill a zero if the value does not exist.