I need to create a Chart Report where I need to display the data rolling 12 months and more than 12 months.For example, my Cognos Report is displaying data from Dec2018 to Dec 2019 but post 2019 it should reflect date from Dec 2019 to Dec 2020.
Also, there is a summary sheet below which has values against KPI's and applying some calculations on those value, I need to show in Report.Like, there is a value in KPI (98765) for Dec 2018 and I need to reflect (98765/1000) above.A sample Report is provided below.
Try this Filter
[Date] >= _add_years(_add_days(current_date, -1), -1)
Then for the measures
Definition for the data item rolling 12
IF([Date] <= current_date)Then([Measure])Else(0)
Definition for the data item post
IF([Date] < current_date)Then([Measure])Else(0)
I did already search in past answers for nearly two days but found no solution. I have a table with a column 'projects', column 'country' and a column 'timeframe'. I want to count the number of projects, grouped by country, which did start before 2017. The data looks like
ProjectID CountryID Time
5 3 Enero/2011 - Diciembre/2020
6 3 June 2017 - December 2020
7 3 June 2017 - December 2030
8 5 NULL
9 11 July 2017 - December 2020
10 11 7/2017 - 12/2020
11 5 2017 June - 2020 January
The problem is the format of the Time, but as it is a large dataset I cannot change the format manually. I tried my best to do something like
SELECT *, COUNT (*)
WHERE (Time LIKE '%XX% - %' AND XX < 2018);
but I cannot find the right way to include the parameter XX in the query. Is there any way to get this done without re-writing all data manually?
Thanks a lot!
Thanks Tripehound - substrings did help! For the Start year
SELECT ID, substr(TimeFrame, instr((TimeFrame),'20'),4) AS ProjectStart
, Count(*) AS NumberProjects
FROM Timeframe
WHERE ProjectStart>"2017";
did do the job; for the end year it was
SELECT substr(TimeFrame, instr(TimeFrame,'-')-1+instr(substr(TimeFrame, instr(TimeFrame,'-')), '20'), 4) AS ProjectEnd,
Count(*) AS ProjectsNumber
FROM Timeframe
WHERE ProjectEnd<"2030";
Done!
I am working on a report in Power BI. One of the tables in my data model collects sensor data. It has the following columns:
Serial (int) i.e. 123456789
Timestamp (datetime) i.e. 12/20/2016 12:04:23 PM
Reading (decimal) i.e. 123.456
A new record is added every few minutes, with the current reading from the sensor.
Power BI automatically creates a Hierarchy for the datetime column, which includes Year, Quarter, Month and Day. So, when you add a visual to your report, you can easily drill down to each of those levels.
I would like to include the "Time" part of the data in the hierarchy, so that you can drill down one more level after "Day", and see the detailed readings during that period.
I have already set up a Date table, using the CALENDARAUTO() function, added all of the appropriate columns, and related it to my Readings table in order to summarize the data by date - which works great. But it does not include the "Time" dimension.
I have looked at the following SO questions, but they didn't help:
Time-based drilldowns in Power BI powered by Azure Data Warehouse
Creating time factors in PowerBI
I also found this article, but it was confusing:
Power BI Date & Time Dimension Toolkit
Any ideas?
Thanks!
Unfortunately, I can not comment on the previous answer, so I have to add this as separate answer:
Yes, there is a way to automatically generate Date and Time-Tables. Here's some example code I use in my reports:
let
Source = List.Dates(startDate, Duration.Days(DateTime.Date(DateTime.LocalNow()) - startDate)+1, #duration(1,0,0,0)),
convertToTable = Table.FromList(Source, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error),
calcDateKey = Table.AddColumn(convertToTable, "DateKey", each Date.ToText([Date], "YYYYMMDD")),
yearIndex = Table.AddColumn(calcDateKey, "Year", each Date.Year([Date])),
monthIndex = Table.AddColumn(yearIndex, "MonthIndex", each Date.Month([Date])),
weekIndex = Table.AddColumn(monthIndex, "WeekIndex", each Date.WeekOfYear([Date])),
DayOfWeekIndex = Table.AddColumn(weekIndex, "DayOfWeekIndex", each Date.DayOfWeek([Date], 1)),
DayOfMonthIndex = Table.AddColumn(DayOfWeekIndex, "DayOfMonthIndex", each Date.Day([Date])),
Weekday = Table.AddColumn(DayOfMonthIndex, "Weekday", each Date.ToText([Date], "dddd")),
setDataType = Table.TransformColumnTypes(Weekday,{{"Date", type date}, {"DateKey", type text}, {"Year", Int64.Type}, {"MonthIndex", Int64.Type}, {"WeekIndex", Int64.Type}, {"DayOfWeekIndex", Int64.Type}, {"DayOfMonthIndex", Int64.Type}, {"Weekday", type text}})
in
setDataType
Just paste it into an empty query. The code uses a parameter called startDate, so you want to make sure you have something similar in place.
And here's the snippet for a time-table:
let
Source = List.Times(#time(0,0,0) , 1440, #duration(0,0,1,0)),
convertToTable = Table.FromList(Source, Splitter.SplitByNothing(), {"DayTime"}, null, ExtraValues.Error),
createTimeKey = Table.AddColumn(convertToTable, "TimeKey", each Time.ToText([DayTime], "HHmmss")),
hourIndex = Table.AddColumn(createTimeKey, "HourIndex", each Time.Hour([DayTime])),
minuteIndex = Table.AddColumn(hourIndex, "MinuteIndex", each Time.Minute([DayTime])),
setDataType = Table.TransformColumnTypes(minuteIndex,{{"DayTime", type time}, {"TimeKey", type text}, {"HourIndex", Int64.Type}, {"MinuteIndex", Int64.Type}})
in
setDataType
If you use the DateKey and TimeKey (like suggested in the first answer) in your fact-table, you can easily generate the date/time-hierarchy by simply putting the time-element in the visualization below the date-element like this
date-time-hierarchy
You will want separate date & time tables. You don't want to put the time into the date table, because the time is repeated every day.
A Time dimension is the same principal as a Date dimension, except instead of a row for every day, you would have a row for every minute or every second (depending on how exact you want to be - I wouldn't recommend including second unless you absolutely needed it, as it greatly increases the number of rows you need - impacting performance). There would be no reference to date in the time table.
E.g.
Time | Time Text| Hour | Minute | AM/PM
---------|----------|------|--------|------
12:00 AM | 12:00 AM | 12 | 00 | AM
12:01 AM | 12:01 AM | 12 | 01 | AM
12:02 AM | 12:02 AM | 12 | 02 | AM
... | ... | ... | ... | ...
I include a time/text column since Power BI has a habit of adding a date from 1899 to time data types. You can add other columns if they'd be helpful to you too.
In your fact table, you'll want to split your datetime column into separate date & time columns, so that you can join the date to the date table & the time to the time table. The time will likely need to be converted to the nearest round minute or second so that every time in your data corresponds to a row in your time table.
It's worth keeping but hiding the original datetime field in your data in case you later want to calculate durations that span days.
In Power BI, you'd add the time attribute (or the hour (and minute) attribute) under the month/day attributes on your axis to make a column chart that can be drilled from year > quarter > month > day > hour > minute. Power BI doesn't care that the attributes come from different tables.
You can read more about time dimensions here: http://www.kimballgroup.com/2004/02/design-tip-51-latest-thinking-on-time-dimension-tables/
Hope this helps.
My approach was to create new column with given formula:
<new-column-name>=Format([<your-datetime-column>],"hh:mm:ss")
This will create a new column and now you can select it with your-datetime-column to create a drill-down effect.
I created a new custom column and set formula=[Timestamp] and change type to datetime.
#"Added Custom" = Table.AddColumn(#"Added Conditional Column16", "TestTimestamp", each [Timestamp]),
#"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"TestTimestamp", type datetime}}),
I have an excel sheet that basically looks like this:
| A | B
1 | 23.12.2013 | 03.01.2014
2 | 20.01.2014 | 25.01.2014
and so forth. The dates stored in start and end could be in the same month but are not necessarily. Simply summing up workdays in a range is not that hard: =NETWORKDAYS(A1;B1) is fine here.
So the question is how do I sum up the work days in a range that belong to a certain month? For the first row for example the result would be 7 for December and 3 for January.
For example, if your bounds are in cells A1 and A2 and you want to intersect the range with December 2013:
=NETWORKDAYS(MAX(A1,DATE(2013,12,1)),MIN(A2,DATE(2013,12,31)))
Using #Taosique's formula (+1) and modifying it a little, you can create a table (which will have to be maintained as and when required) to track such things down.
I would create several columns with headers containing dates, being 1st December 2013, then 1st January 2014, 1st February 2014, etc.
Then in cell C2, use the formula:
=IFERROR(MAX(NETWORKDAYS(MAX($A2,C$1),MIN(D$1-1,$B2)),0),0)
Then drag it down and across to fill for the other columns (months) and people. See the google spreadsheet I made here if you wan to see it.
Google Spreadsheet has some limitations on formatting, but you can 'hide' the date of the column by turning it into a month by formatting it as mmm-yy in Excel.
Given the following dimensions specifications in Crossfilter's API - https://github.com/square/crossfilter/wiki/API-Reference
1.) The function must return naturally-ordered values
2.) .....incomparable values such as NaN and undefined are not supported
How would one go about charting a crossfilter (using dc.js) with two dimensions - one with daily data (7 days a week), and another with business-day data (5-days a week)? The data structure implies that the business-day data will have gaps on the weekend which should violate the specifications above.
For example, if I want to compare a company's store sales (7 days/week) vs its stock price (5 days + gaps on Saturday and Sunday), how would i go about it? The goal would be to have two dc.js charts filtering each other, but having data that isn't perfectly matched up i.e. the first chart will show sales data from Jan 1 till Jan 31 (7 days a week), while the second chart will show stock price data from the first till the last business day in Jan (excluding weekends).
Your stock data would likely include no data for Saturday and Sunday. This is is different from having a data row with stock price as NaN.
For example: If you plotted the stock data on a row chart with the days of the weeks for the categories, then there would be no bars for saturdays and sundays.
Here is a crude example: DC.JS example of days of week chart
I made sure that no rows were added for saturdays and sundays:
if ((stockDate.getDay() != 6) && (stockDate.getDay() != 0))
The resulting row chart has no row for Saturday or Sunday.
You could explore filtering your data, as I did, so you preselect what you want to show. Remember to include the additional code which preserves the bins.
Hide Specified Row in dc.js rowchart