How can i modify DATEDIFF to find results in the past? - visual-studio-2012

I have created a Visual Studio report (database is dynamics crm 2011). This report shows me from now (today) all elements 13 months in the past.
DATEDIFF(Month, CRMAF_FilteredQuote.createdon, CURRENT_TIMESTAMP) <=13;
How should I modify this statement to get the results from the final day of the previous month? For example all documents from the 30th September through to 1st August?
Thank you very much for your ideas.
Peter

You can get last day of previous month using below given query
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
To find all documents created between two dates (last day of previous month and today), use below given query
SELECT *
FROM Entity_Name
WHERE CreatedOn Between DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) AND GETDATE()

Related

Cognos report studio last day of month

I'm using the following filter, but it's not including any transactions from the last day of the month. I think this filter assumes 12:01am. I need to include through 11:59:59PM.
[TRL_DATE]<=_last_of_month(?ReportDate?)
cast([TRL_DATE], date) <= cast(_last_of_month(?ReportDate?), date)

Amazon Quicksight Dynamic date filter

so everyday I receive sales data from the previous day. So today November 15 I have data from July 2021 until November 14 2021. What I want is to show this data for the current month by aggregating by day. I use a quicksight visual with a MTD (Month To Date) filter. Everything is fine so far.
The problem is on each first date of the month, I see "No Data" on my visual which is normal since I do not have any data from the current day/month but as I said earlier from the day before.
So what I want to achieve is:
Each 1st of current month: show data from the whole previous month
From 2nd to last day of current month: show data from the current month
Can someone help me please to know how I can achieve this?
I looked for ways to do this and I found dynamic default parameters but this option is not fine with me since I have to fill a username column according to the documentation (https://docs.aws.amazon.com/quicksight/latest/user/parameters-set-up.html) and I have many users so it will be not interesting to list all of them.
You can assign parameters to a group rather than a specific user which is much quicker
There is new functionality which allows you to set today or beginning/ending of month/quater/year as default.
See screenshot:
enter image description here

Cognos Query to calculate a run date

So in my Cognos report I have a column 'Last Separation Date'. I want run a query on that column to calculate to all persons currently employed or separated from employment within the last two years. However, this date query should auto run to the day I'm running the report. For example. I run the report today 2/22/2020 and view data for the last two year till 2/22/2018. I login few days later to view the report on 3/1/2020. The report should pull data from 3/1/2018.
Create a filter with the between function using current date and some expression which determines a date two years in the past.
https://www.ibm.com/support/knowledgecenter/SSEP7J_11.0.0/com.ibm.swg.ba.cognos.ca_mdlg.doc/c_sql99_current_date.html#sql99_current_date
_add_years or _add_days might be handy as they take negative numbers.
Using the previous answers suggestions, your detail filter would be similar to
[Last Separation Date] between current_date and _add_years(current_date,-2)

Cognos Report totaling hours over time

I'm pretty new to Cognos 10 Report Studio so this may be a fairly simple question but I have been unable to find on answer so far.
In my database I have the hours a person has worked in a two week pay period, as well as what month a pay period exists in. I would like to total the over any period of months.
For example a user is prompted to choose a range of time, and they may select a start month of January of some year, and an end date of June of the same or some later year, and then the report would have a column that displays the sum of hours worked by a person between that time frame.
So in essence the sum of hours for every pay period in a given range of dates.
Thank you very much for your help.
If you want a list (or crosstab) with the User, year, month, and total hours in each month
Create a new data item (maybe something called - Hours by Month) defined as:
total([hours] for [Year], [Month], [User])
The function allows you to define the scope so the SQL is structured to give you the answer grouped the way you want

Extract year from cognos report expression

I want to extract current year, last year in report expression field but am not able to get it.
date2timestamp(Today()) and Today()
This works fine to get date
_add_years(date2timestamp(Today()),1) and extract("year",Today())
but this shows error.
I wanted to show 2016, 2015 dynamically in my report as heading of cross-tab node.
If you use layout calculation try
substring(date2string(Today()),1,4)
for current year. And
string2int32(substring(date2string(Today()),1,4)) - 1
for previous year.
for current year:
extract('year', date2timestamp(today()))
for prior year:
extract('year', _add_years(date2timestamp(today()), -1))
This will give you an integer value that you can format using the normal Data Format options in the date item properties, for example to remove the thousands comma if desired.
Make a query with two data items.
For the previous year, one data item will have:
extract (year, _add_years(current_date, -1))
And for the current year:
extract (year, current_date).

Resources