I am trying to create a column graph that regardless of whichever date filters are selected, it will always show only the past 30 days worth of data. I have the date values in Excel format as the field [Raw Excel Date]. No idea how to do this, as I am relatively new to Qlikview development. Any help is greatly appreciated.
Some additional info- The expression I am using right now that is displaying the trend across all dates is simply COUNT([ThingID]).
Lets assume that the data look like this:
(not sure in what format is the date that you have. I assume that the format is YYYY-MM-DD)
Raw Excel Date, ThingID
2014-01-01 , 10
2014-01-02 , 20
2014-01-03 , 30
2014-01-04 , 40
2014-01-05 , 50
Then you need to create one variable (vMaxDate in my case):
= date(max({1} [Raw Excel Date] ), 'YYYY-MM-DD')
The above variable will always return the max possible data in your data set no matter the selections (not only the data selection but any selection)
Then in your chart you can use expressions like this:
count({< [Raw Excel Date]=, [Raw Excel Date] = {"<=$(=( date(vMaxDate)))>=$(=( date(vMaxDate - 30)))"}>} [ThingID])
The set analysis in the expression will ignore all selections in [Raw Excel Date] field and then will "select" (internally) only the values in [Raw Excel Date] which are less than (and equal) to the value in vMaxDate and bigger than (and equal) vMaxDate-30 values.
Stefan
Related
So, I have a Power BI report where I have a slicer with values such as :
202005
202004
202003
202002
202001
Pacing
Every month, the data gets added and the category is incremented by 1. i.e in June, I'll have 202006 as well.
I have a report where I want the data to be filtered by last 3 months and Pacing.
i.e in May, default selection should be 202004, 202003, 202002, Pacing
in June, default selection should be 202005,202004,202003, Pacing
In other words, I want default selection of: max month-1, max month -2, max month -3 and pacing.
Currently, I am manually making the selection and saving the report and then publishing it again. But to do so, I have to refresh data every time to get updated values of the month and it has increased my file size to a great extent because the data is imported in my report. I believe that my report can crash anytime if I continue this.
While you can't yet directly set slicer defaults, there are some workarounds.
However, relative date filtering or Top N filtering on a slicer might help:
If you don't need all the old data, you can keep your file size from continuing to grow by filtering the dates in the query editor before they are loaded to the model.
I am attempting to display all the dates within a range even if they do not have data for the particular date.
Our employees do work 24/7 365 ( like everyone else) so there are dates within my time range that wont pop up. What i have tried is to add and exception that states even if the date has a null to display that particular date.
Currently i have a crosstab with the row being the numbers of items completed and the columns being the date that the item was completed.
For a visual:
04/01/19 04/02/19 04/03/19
1 2 3
I would like to continue that till the end of my range (the month) but my data skips if nothing was completed for that date.
What i currently have:
04/01/19 04/04/19 04/05/19
1 6 8
For the rows I have this in the formula bar for my row.
If [Items Completed]> 0 Then [Items Completed)] Else 0
For the columns I have this in my formula bar
If IsNull([Completed Date]) then 0 Else [Completed Date]
Thinking this would give me a 0 in those columns where nothing was done.
You need to create a variable and use the TimeDim function like this...
All Dates = TimeDim([Completed Date])
Then replace [Completed Date] in your table with the [All Dates] variable. You can name it whatever you want. This will result in blank values for the dates for which you do not have data. If you want to have zeroes display for the dates with no data you can apply a custom format setting "Undefined" to "0".
You can find a more thorough explanation with possible variations here.
Enjoy!
The TimeDim method was the basis for me achieving what I needed - namely a line chart that displayed zero values if no one had completed a training course on a particular date in my range. I work in Learning Management System software so this is often required.
The object in my case is called [Course Completed Date (Success)], so here's my variable (which is a dimension, not a measure):
=TimeDim([Course Completed Date (Success)])
Note in my screenshot how the zeros and now displayed. Previously they were missing.
I hope someone could help with this?
I am building a report based on a stored procedure that has the following clause in it
where accountingperiod = #Accountingperiod or createddate between #Startdate and #Enddate
#Accountingperiod will be in the following Format 'Oct 2017'
#Start and #Enddates are just generic date formats.
I basically want my report to load and have the option to select whether the user wants to filter the report using the #Accountingperiod parameter or the date parameter (as both bring back entirely different data). Once the user has selected which one is to be used, the parameters (for example, #accountingperiod) will be available for selection.
How can this be achieved? Apologies if this is a silly question, I am quite new to SSRS!
Thank you
There are several ways to do this. The simplest would be to do it in the Stored Procedure and just test if Accounting Period has been set, if so use that, if not use the date range but that might not be intuitive for the user as they could select an accounting period AND a date range without realising that the date range would be ignored.
The most elegant solution would be to set the start and end dates based on the accounting period and have another entry in your accounting period list called 'Date Range' or 'Any' etc.
This assumes you can lookup or calculate the start and end dates for each accounting period. For the sake of simpicity in this example we'll assume that you have a table (say myAccPeriodTable) with the periods and date ranges in, something like this..
AccPeriodID AccPeriod StartDate EndDate
1 2017-Q1 2017-01-01 2017-03-31
2 2017=Q2 2017-04-01 2017-06-30
3 2017=Q3 2017-07-01 2017-09-30
etc...
Create a dataset (lets call it dsAccPeriods) with the following query
SELECT AccPeriodID, AccPeriod FROM myAccPeriodTable
UNION SELECT -1, 'Use Date range'
ORDER BY StartDate
You Accounting period Parameter (assume this is called #AccPeriodID) Available Values would be from a query and point to dsAccPeriods
The Value would be the AccPeriodID field and the Label field would be AccPeriod
Now create two more datasets say, dsDefaultStartDate and dsDefaultEndDate with the following queries respectively.
SELECT ISNULL(StartDate, 1999-01-01) AS StartDate From myAccPeriodTable WHERE AccPeriodID = #AccPeriodID
and
SELECT ISNULL(EndDate, 2020-12-31) AS EndDate From myAccPeriodTable WHERE AccPeriodID = #AccPeriodID
For your 'StartDate' parameter (assume its called #StartDate) the Default Value would simply point to the dsDefaultStartDate dataset and do the same with #EndDate pointing that to dsDefaultEndDate.
Now when the user selects a start date, the two data parameters should be populated with hte correct dates so your Stored Proc can simply filter based on the #StartDate and #EndDate parameters. If the user chooses the use Date Range option then the default dates will be set to whatever dates you specified in the dsDefaultStartDate and dsDefaultEndDate datasets.
Of course there is a chance that the user selects a real accounting period and then changes the date ranges. There are things you can do to avoid this but one step at a time !
I've written this answer without testing anything so there could be some mistakes but hopefully it will point you in hte right direction. If you have any issues leave a comment.
I have a matrix report called Store Sales which is made up of:
STORES in the row group
DATES in the column group
Sum of SALES in the values group
The DATES column is formatted using the following expression:
=format(Fields!DATES.Value, "MMM yyyy").
The matrix report also has 2 parameters #Start and #End. This all works great but I then added a linked report (Sales Store Details) so that the user can click on the SALES value for any purchase by month and store. The linked child report (Sales Store Details) uses the #Start and #End parameters from the original report (plus an additional #Store parameter) but this is where I run into problems. Rather than bringing me the purchase details for a particular store and month it brings me back everything from the time period selected from the original date parameters. So say I originally selected 2015-01-01 to 2015-06-30 with the #Start and #End parameters from the Store Sales report. When I then select on my FEB 15 value in my matrix report the drill down linked report doesnt just give me Feb 15 data but all the other months data too ie Jan-Jun 15. I understand that the original report parameters specified the Jan-Jun 15 date period but surely when I select on the Feb value in the matrix report that's what my linked report should drill down too right?
Any help would be really appreciated.
It sounds like you're passing the original #Start and #End parameters from the parent report. If so then you're passing the original date filtering parameters so it shouldn't be surprising that the date filtering on the child report is the same.
If you want to limit the child report's date filtering to only the month of the row being clicked you'll need to pass through the date value for that row instead of the original parameters. I'm not sure how your data set is structured but I assume there is some date column you use to determine the appropriate filtering to use.
I'm trying to obtain the total amount of time difference from two timestamp columns (datetime)
I currently have a Table 1 setup like the following:
Time_Line_Down => datetime
Time_Line_Ran => datetime
Total_Downtime => Computed column with formula:
(case when [Time_Line_Down] IS NULL then NULL else CONVERT([varchar],case when [Time_Line_Ran] IS NULL then NULL else [Time_Line_Ran]-[Time_Line_Down] end,(108)) end)
Every time some conditions occur, I am copying those three columns (I have more columns but the problem is on this ones) into another Table 2 originally setup like the following:
Time_Line_Down => datetime
Time_Line_Ran => datetime
Total_Downtime => datetime
I then use an excel spreadsheet to "Get External Data" from SQL Server and use a pivot table to work with the data.
Example
Time_Line_Down = 2015-02-20 12:32:40.000
Time_Line_Ran = 2015-02-20 12:34:40.000
Total_Downtime = 1900-01-01 00:02:00.000
Desired Output
I want the pivot table to be able to give me a Grand Total of downtime from all rows in that table
Let's say it was forty five hours, fifty minutes and thirty seconds of accumulated downtime it should read like (45:50:30)
The problem:
Even if I format the Total_Downtime column in the excel pivot table as h:mm:ss to read like this:
Total_Downtime = 0:02:00
As rows accumulate and the Grand Total is calculated the "Date" part of the timestamp is messing the result is the total exceeds 24 hours
What I have tried
I changed the data type format of column Total_Downtime in Table 2 to time(0) so that it won't send the "Date" part, only the "Time" part of the timestamp, it is working and reads out 00:02:00
But now all the values in my pivot table on excel for that column are 0:00:00 no matter what value is actually in the SQL table.
Any suggestions?
You can use the Excel time format [h]:mm:ss which can go beyond 24 hours.
Alternatively, you can use the SQL function DATEDIFF to get the total downtime in seconds, and then convert that to however you need to display it in Excel, e.g.
case when [Time_Line_Down] IS NULL then NULL else case when [Time_Line_Ran] IS NULL then NULL else datediff(ss, Time_Line_Ran, Time_Line_Down) end end
I don't think you need the CASE statements here, you can just use
datediff(ss, Time_Line_Ran, Time_Line_Down)
Thank you all for your help,
I went ahead an tried the function DATEDIFF as suggested, I changed Table 1 computed column formula and Table 2 Total_Downtime column data type to int. Once imported into excel this numeric value needed some extra calculations.
In principle is the best answer and should work for anyone trying to calculate the difference from two timestamps, as mentioned before, is pretty straight forward.
But in my situation I needed to maintain two things:
1) The format 00:00:00 for the column Total_Downtime in Table 1, which changed to an integer value when using DATEDIFF
2) The pivot table Total_Downtime column format [h]:mm:ss (suggested by TobyLL) in excel, which required several calculations to convert from seconds
Solution
After learning that every time I copied from Table 1 to Table 2 the computed value (e.g. 00:02:00) changed to 1900-01-01 00:02:00.000 and that when imported to Excel it equaled to 1.001388889, I decided to force the "Date" part of the time stamp to be 1899-12-31 so that Excel would only calculate the Grand total in the pivot table with the "Time" (decimal) part.