I need to calculate a logic on the basis of Weekending Date in a report for the Monthly report
We have two pages of reports in the report studio
Weekly Report with the weekending data (Example: 26/02/2021) Day 1 of the week starts from Saturday to Friday
Monthly Report with the month data. I know the monthly calculation to get the data current month data using the below
TRANSACTION_DATE between _first_of_month (_add_months (current_date,0) and _last_of_month (_add_months (current_date, 0)
But here the requirement is how can we calculate based on the Weekending Date. The requirement is to show the previous month data even in the 1st week of next month (New Month)
that is from (01-Mar-2021 to 05-Mar-2021) since the weekending of the weekly report is showing the data for 26/02/2021 (Friday).
This should work dynamically since this is a scheduled report and we are not having any prompt page to select the date ranges since the report take to long to execute.
Please share your ideas and thoughts on this.
Your help is much appreciated.
Yours Sincerely
Cognos Man
We need to know
day of the week
first week of the month
current week
prior month range
current month range
For the example, we will refer to the transaction data item as [Date]
To get the week, we are going to create a data item [Week of Year] like this:
_week_of_year ([Date])
To compare, we are going to create a data item [First of Month]
_first_of_month (Current_date)
That will allow us to create another data item [First of Month Week]
_week_of_year ([First of month])
Almost there, we need the day of the week [DOW]
_day_of_week (Current_Date,1)
We can create a data item just to make the filter a little easier, let's call it [Test] with an expression like this:
IF ([Week of Year] = [First of Month Week] and [DOW] < 6)Then('Prior')Else('Current')
Now we can create a filter
([Test] = 'Prior' AND
[Date] between [Prior Month Start] and [Prior Month End])
OR
(([Test] <> 'Prior' AND
[Date] between [Current Month Start] and [Current Month End])
To get the starting points:
[Current Month Start] definition would be
_first_of_month (Current_date)
[Current Month End] definition would be
_add_days (_first_of_month (_add_months(Current_date,1)),-1)
Prior month would be similar, just reduce the month, to get PrevDate
_add_months (Current_date, -1)
For example, [Prior Month Start]:
_first_of_month ([PrevDate])
For example, [Prior Month End]:
_add_days (_first_of_month (_add_months([PrevDate],1)),-1)
Related
I a process have a Start date of 1/1/2022 and end date of 3/15/2022, date is in it's own field.
Now I have a field for every Month in the Year: J F M A M etc.
I want to calculate that my process covers 100% of January and February and 50% of March. In order to calculate this, I added the start and end date for each month below the field like this :
Screenshot
Any help how I can calculate this would be appreciated.
I am facing a relatively trivial problem. I have a list of start dates for each fiscal year. For example, 03.01.2019 for the 2019 financial year or 30.12.2019 for the 2020 financial year.
Now I want the calculated column in my calendar table (Power Pivot) to count up from the start date from 1-53 per week until the next start date.
It would look like this:
03.01.2019 - 1
04.01.2019 - 1 ....
Does anyone know how to do this?
You cen get the ISO 8601 weeknumbers by adding 21 in the optional part. Here a quick example I created. But if you also have dates which start in the middle of the year you should go with a calendar, like #Kosuke Sakai posted:
Generally, the recommended approach for this requirement is to prepare a fiscal calendar in the data source (DWH, MDM, Excel, or somewhere), rather than to calculate with DAX.
Having said that, it is possible with DAX.
Assuming you have a table like below. (Let's call it FiscalYears)
First, you need to add FiscalYear calculated column to your Calendar table with following formula.
FiscalYear :=
VAR CurrentDate = [Date]
RETURN CALCULATE (
MAX ( FiscalYears[FiscalYear] ),
FiscalYears[StartDate] <= CurrentDate
)
Then, you can use this to calculate WeekNumberInFiscalYear column.
WeekNumberInFiscalYear :=
VAR StartDate = LOOKUPVALUE (
FiscalYears[StartDate],
FiscalYears[FiscalYear],
[FiscalYear]
)
RETURN DATEDIFF ( StartDate, [Date], WEEK ) + 1
The result will be looking like below.
I have created a report with a slider that filters on year. The client however would like to not see the future month zero values. I am not quite sure how to modify the year and month filters so that if [fiscal year] = (year(current_date) then [Fiscal Year Month Number] to (month(current_date) I have attached a couple of screenshots. "Period" in the X axis is sorted by Fiscal Year and Fiscal Year Month Number.enter image description here
Thank you
I was trying to add this as a filter when I should have added it as a new measure.
if([Fiscal Year]=[Current Year] and [Fiscal Year Month #]<=[Current Month]) then ([Corp FY Data])
else
if([Fiscal Year]=[Current Year] and [Fiscal Year Month #]>[Current Month]) then (null)
else
if([Fiscal Year]>[Current Year]) then (null)
else
if([Fiscal Year]<[Current Year]) then ([Corp FY Data]) else (0)
Problem resolved. Yeah me. ;)
Using the Start Date and End Date of PTO - Personal Time Off Days Used only count days used up to end of prior month, excluding weekends and U.S Holidays in that certain month. Example of a Holiday is Sept 7th 2015 in the United States.
My goals are:
Create a Data Item Month End Personal Time Off Days used.
Of course it should be getting the number of PTO Days USED from the prior month only.
Exclude weekends in that certain month. So if the Resource takes a Leave on Friday and Monday, Saturday and Sunday should not be excluded in the computation.
How to exclude U.S Holidays, if this is possible that's great but if it's not possible then I'm okay with numbers 1, 2 and 3.
I have created a Data Item column that captures the PTO days used. But this is good for Year to date.
Case when [PTO Info].[PTO Audit].[PTOAuditTypeId] = 31571
and [PTO Info].[PTO Audit].[TimeOffTypeId] = 31566
then [PTO Info].[PTO Audit].[PTODays]
when [PTO Info].[PTO Audit].[PTOAuditTypeId]=31572
and [PTO Info].[PTO Audit].[TimeOffTypeId] = 31566
and [PTO Info].[PTO Audit].[PTODays] < 0
then abs([PTO Info].[PTO Audit].[PTODays] )
else 0 end
I'm not sure if the query below can help.
A calendar table is really going to help you out here. Assuming it has one record per calendar date, you can use this table to note weekends, holidays, fiscal periods vs Calendar periods, beginning of month/end of month dates. A number of things that can help simplify your date based queries.
See this question here for an example on creating a calendar table.
The main point is to create a data set with 1 record per date, with information about each date including Month, Day of Week, Holiday status, etc.
Without a calendar table, you can use database functions to generate your set of dates on the fly.
Getting the Month number for a date can be done with
extract([Month], <date field goes here> )
Getting a list of values from nothing will be required to generate your list of dates (if you don't have a calendar table with 1 record per date to use) will vary depending on your source database. In oracle I use a 'select from all_objects' type query to achieve this.
An example from Ask Tom:
select to_date(:start_date,'dd-mon-yyyy') + rownum -1
from all_objects
where rownum <=
to_date(:end_date,'dd-mon-yyyy')-to_date(:start_date,'dd-mon-yyyy')+1
For Sql Server refer to this stackoverflow question here.
Once you have a data set with your calendar type information, you can join it to your query above:
join mycalendar cal on cal.date >= c.PTOStartDate
and cal.date <= c.PTOEndDate
Also note, _add_days is a Cognos function. When building your source queries, try and use Native functions, like in oracle you can 'c.PTOStartDate + a.PTODays'. Mixing Cognos functions with native functions will sometime force parts of your queries to be processed locally on the Cognos server. Generally speaking, the more work that happens on the database, the faster your reports will run.
Once you have joined to the calendar data, you are going to have your records multiplied out so that you have 1 record per date. (You would not want to be doing any summary math on PTODays here, as it will be inflated.)
Now you can add clauses to track your rules.
where cal.Day_Of_Week between 2 and 6
and cal.Is_Holiday = 'N'
Now if you are pulling a specific month, you can add that to the criteria:
and cal.CalendarPeriod = '201508'
Or if you are covering a longer period, but wanting to report a summary per month, you can group by month.
Final query could look something like this:
select c.UserID, cal.CalendarPeriod, count(*) PTO_Days
from dbo.PTOCalendar c
join myCalendar cal on on cal.date >= c.PTOStartDate
and cal.date <= c.PTOEndDate
where cal.day_of_week between 2 and 6
and cal.Is_Holiday = 'N'
group by c.UserID, cal.CalendarPeriod
So if employee with UserID 1234 Took a 7 day vacation from thursday June 25th to Friday July 3th, that covered 9 days, the result you get here will be:
1234 201506 4
1234 201507 3
You can join these results to your final query above to track days off per month.
In my excel file, we are tracking items in for repairs with their corresponding dates of arrival. The dates start in A3 and continue to A23. I need a function to output how many items arrived each month based on their date of arrival in C45 (July), D45 (August), ect. Is this even possible?
There are no values corresponding to these dates. That is why my previous attempts at using the LOOKUP function have failed. Thanks.
Arrival Date
7/10/2012
9/10/2012
9/18/2012
9/18/2012
9/19/2012
Total Failures July '12 August '12 September '12
Historical 1 0 4
Put =SUMPRODUCT(--(MONTH($A$3:$A$23)= 7)) in C45
Put =SUMPRODUCT(--(MONTH($A$3:$A$23)= 8)) in D45
courtesy: www.chandoo.org