Tableau report count total number of articles based on article's publish and unpublish date, filter by parameter control date range - aggregation

I am newbie to Tableau reporting and need your help to enlighten me on Tableau.
I am looking for a way to count total number of articles based on article's publish and unpublish date, filter by parameter control date range.
I have provided the sample data and sample report for the challenge I am facing.
Basically every article will have publish and unpublish date, I need to count total number of article for each day, based on the date range user select from parameter control.
E.g. If user choose to show article number from 1st Jun to 5th Jun, report X-axis will only from date from 1st Jun to 5th Jun.
I have tried to use calculated field, but seems only can calculate for a day.
2 challenges I see:-
1) How to loop through date range for parameter control
2) How to aggregate total article each day based on publish data and unpublish date
Sample data:-
[ArticleNo][Publish Date][Unpublish Date]
110 2014-May-01 2014-Jun-03
111 2014-Jun-02 2014-Jun-03
112 2014-Jun-03 2014-Jun-30
Sample report format, bar/line graph:-
Report date range : 2014-Jun-1 to 2014-Jun-5 (Parameter Control)
Number of Article Published
^
4 |
3 | X
2 | X X
1 | X X X X X
---------------------------------------------->
| 1-Jun 2-Jun 3-Jun 4-Jun 5-Jun
Report Date Range
I tried to use the following calculated field, but seems can only calculate for a day:-
My calculated field
IF ([Date From] >= [Publish Date] and [Unpublish Date] <= [Date To]) THEN
DATEDIFF('day',[Date From],[Unpublish Date]) + 1
ELSEIF ([Date From] >= [Publish Date] and [Unpublish Date] >= [Date To]) THEN
DATEDIFF('day',[Date From],[Date To]) + 1
ELSEIF ([Date From] <= [Publish Date] and [Unpublish Date] <= [Date To]) THEN
DATEDIFF('day',[Publish Date],[Unpublish Date]) + 1
ELSEIF ([Date From] <= [Publish Date] and [Unpublish Date] >= [Date To]) THEN
DATEDIFF('day',[Publish Date],[Date To]) + 1
END
Thanks for your help first. Cheers.

One solution is to first reshape your data to make the reporting easier, possibly using a custom SQL data connection or data blending or pre-processing.
The custom SQL approach can use a UNION ALL clause to combine a table with itself; data blending can do similar tricks on the client side by having two similar copies of the connection.
Here is a long but good thread discussing a similar, but not identical, problem set.
http://community.tableausoftware.com/thread/120614
Hope this gets you started - no time to write more detail right now.

Related

How to get last 4 weeks dates in power query (Excel or Power BI)

Using Power Query coding language AKA “m”, write a statement to add a custom column that shows a bit value of whether a Delivery Date is in the past 4 weeks including up to the current date.
Please #help
Result in blank query:
5/13/2021
5/12/2021
5/11/2021
5/10/2021
5/09/2021
Until
4/19/2021
If I understand your requirement correct, you need the custom column code-
if Duration.Days(DateTime.Date(DateTime.LocalNow()) - [Delivery date]) <= 28 then 1 else 0

FY vs last FY Cognos 11

I am looking to generate report in Cognos 11 for attended appointments for this FY vs last FY for the same time frame. For example of I am running report on 1st June 2021, I should get data for sum of appointments of April and May 2021 and sum of appointments of April and May 2020.
Please let me know how can I set the date filter.
Thanks
You didn't provide any context. There are many ways to do this. Just providing a filter expression won't work because I don't know what the rest of your report looks like.
Describing such a general solution for Cognos in plain text is not simple. I'll also assume that, since you are using Cognos, the database structure is a star schema containing a time dimension with columns named [FiscalYear] and [FiscalMonthNumber] that are integers. Also, that your fiscal year runs from January 1 to December 31.
Using Cognos functions:
[FiscalYear] * 100 + [FiscalMonthNumber]
between
_year(_add_months(current_date, -2)) * 100 +
_month(_add_months(current_date, -2))
and
_year(_add_months(current_date, -1)) * 100 +
_month(_add_months(current_date, -1))
or
[FiscalYear] * 100 + [FiscalMonthNumber] + 100
between
_year(_add_months(current_date, -2)) * 100 +
_month(_add_months(current_date, -2))
and
_year(_add_months(current_date, -1)) * 100 +
_month(_add_months(current_date, -1))
Using Cognos macros:
[FiscalYear] * 100 + [FiscalMonthNumber]
between
#timestampMask (_add_months($current_timestamp, -2), 'yyyymm')#
and
#timestampMask (_add_months($current_timestamp, -1), 'yyyymm')#
or
[FiscalYear] * 100 + [FiscalMonthNumber] + 100
between
#timestampMask (_add_months($current_timestamp, -2), 'yyyymm')#
and
#timestampMask (_add_months($current_timestamp, -1), 'yyyymm')#
The advantage of using the Cognos macro is that the value is computed once before sending to the database server, rather than the database server computing it for every row.
Assumption that you have a data item like invoice date, etc, for the example this will be [Date] but you could change the filter to what makes sense based on your data items
The filter could use a date prompt with a parm i.e. PrmDate or use Current_date
see explanation below
Filter should look like:
([Date] between [CurrentStart] and [CurrentEnd])
OR
([Date] between [PriorStart] and [PriorEnd])
Create some data items to make this a little easier
Offset, note: the offset allows you to change your starting month/period
This would be for January
extract(month, current_date) -1
This would be for April
extract(month, current_date) -4
CurrentStart
_first_of_month (_add_months(current_date, -[Offset]))
CurrentEnd, note: if you don't want a prompt, just swap ?PrmDate? with Current_date
_add_months(?PrmDate?,-1)
PriorStart
_add_years([CurrentStart], -1)
PriorEnd
_add_years([CurrentEnd],-1)

Calculated Column that counts from 1-53 per week from specific start date

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.

How to Filter individual columns within a Cognos Report

All data are coming from one table. Date is based on the creation_date field of the table. I would like to create a report similar to the example below:
No. Prior to No. On
10/01/2015 10/1/2015 Total No.
a 5 1 6
b 10 3 13
c 1 0 1
I could not figure out how to display the combine results on the same "Report Page". I have to create 2 report pages one is for the prior date and the other is for the date "on".
Ok. If I understand your data correctly do this.
In your report create query with query items:
Type (a,b,c etc)
[No. Prior to 10/01/2015] with Aggregate Function = 'Total' and with expression
case when creation_date < to_date('10/01/2015', 'DD/MM/YYYY')
then 1 else 0 end
[No. On 10/1/2015] with Aggregate Function = 'Total' and expression
case when creation_date >= to_date('10/01/2015', 'DD/MM/YYYY')
then 1 else 0 end
[Total No.] with expression
[No. Prior to 10/01/2015] + [No. On 10/1/2015]
And create simple table with this values.
Or you can try to do it with crosstab.

How do I get the Month End Personal Time Off Days used?

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.

Resources