Past 5 week calculation in WEBI (BO 4.0)? - business-objects

I am facing issue in calculating past 5 week data based on current date (excluding currrent week)
For e.g:
Suppose we are in 40th week of this year, I need to get the sum of all the transactions for the previous 5 weeks (39, 38, 37, 36 & 35).
Currently calculating based on the calendar day but as Calendar day is giving the granular level of data, inorder to increase the performance I need to use the calendar week (sample data like (2012/40).
Is there a way to do this?

I'd construct a flag field (either in the back-end or in the universe) using datediff (in SQL Server terms).
Failing that, you could construct a variable in Web Intelligence using the Week function.
Pseudo-code but something like:
=IF(Transaction_Date < Week(CurrentDate()) AND Transaction_Date >= (Week(CurrentDate())-5); "TRUE"; "FALSE")

Related

How do I tell google sheets to only make a calculation after a certain time period?

Context
So I am currently building a database of data for financial assets to conduct some machine learning from to build trading signals. I am trying to calculate the geometric mean but over a given period (monthly). I want to tell google sheets to only calculate the geometric mean after every month. I tried using this formula to no avail:
=IF(last date of the month - first date of month = total days in a month,
GEOMEAN(filter(abs(range),abs(range)>0)),""))
** There were values in the last date of the month - first date of month = total days in a month **
It ended up doing it for every day for the 10 year data set.
** Update
This is the data:
Date Close Cleaned Data Returns Gross returns Geometric average returns
13/11/2015 280 -0.0267 0 1
16/11/2015 280 -0.0267 0 1
17/11/2015 280 -0.0267 0 1
...
23/12/2016 296.4 0.0236 -0.1561348935 0.8438651065
28/12/2016 295.2 0.0199 -0.0770931339 0.9229068661
29/12/2016 294.7 0.0183 0.03341318035 1.03341318
30/12/2016 294.9 0.0190 0.3718276303 1.37182763
Problem (UPDATE)
How do I create a function to let google sheet do calculations only for the last day of every month for a given time series data? Say within this time period, (1 year) I want to calculate the geometric mean for each month in this period and for new data I might want to add later in the future.
To do this you will have to set a trigger event. This is found within the script editor under the edit tab, second to last option.
Image of where to find the trigger manager: It's in spanish, but it will be found in the same place
Once there, click on add trigger, which will be found on the bottom right corner. The first option will ask you which function do you want to run from the bound script. Then select the source of the event and select according to time (My platform is in spanish so I'm trasnlating it you might have it written differently). Then it will prompt you: if you want it to be at an exact date and time, every minute, every hour, day, week and month. Select month and select the day of the month you want the trigger to happen in the next prompt and select the time for the last prompt, then click save.
Finding the last day of a month:
function lastdayOfMonths() {
let html='';
let td=new Date();
for(var i=0;i<12;i++) {
let dt=new Date(td.getFullYear(),td.getMonth()+i+1,0);
let dts=Utilities.formatDate(dt, Session.getScriptTimeZone(),"E MMM dd,yyyy");
html+=Utilities.formatString('<br />%s',dts);
}
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Last Days of Months for next year");
}

Grafana: Convert text box(Template Variable) to integer

I've created a dashboard in grafana which shows the average availability and utilization of a machine. I also want to include the moving average and I've been asked to enable the user to determine the interval of the moving averagein weeks.
In order to do this I would like to use a text box template variable and convert it to an integer. The graphs are and the queries are grouped per days. The moving average is determined based on the average availability per day. Therefore, I would like to do this calculation on the template variable: ([[MA_interval]] * 7) - 1
My code looks like this:
Select AVG(avgAvailability) OVER(ORDER by day ROWS BETWEEN [[MA_interval]] PRECEDING AND CURRENT ROW) AS "Moving Average of Availability"
I would like to do this calculation on the template variable:
([[MA_interval]] * 7) - 1
Where [[MA_interval]] is the interval in weeks and 7 is the number of days in a week.
Could anyone help me out? I am using a MariaDB server as database.

Interesting SSRS parameter discovery when using subscriptions

I have recently been putting together an SSRS report that will run every 15 minutes for the previous 15 minute 'chunk' of time. In essence a very straight forward and simple report that will run via an automated subscription.
I was using Microsoft SQL Server 12 Report Builder Version 3.
I was alerted to an issue with the output csv when my recipient reported being sent blank files, most odd considering the report generated as expected when run manually.
Long story short, it was the expressions I was using to generate the From and To dates. Manual runs produced data, subscription runs did not.
Original parameters
FromDate
dateadd(DateInterval.Second, (second(now()) + 900) * -1, dateadd(Dateinterval.Minute, (minute(now()) mod 15) * -1, now()))
ToDate
dateadd(DateInterval.Second, (second(now()) + 1) * -1, dateadd(Dateinterval.Minute, (minute(now()) mod 15) * -1, now()))
New Parameters
FromDate
dateadd(DateInterval.Minute, -15, dateadd(DateInterval.Minute, cint(datediff(DateInterval.Minute,today(),now()) / 15) * 15, today()))
ToDate
dateadd(DateInterval.Second, 899,Parameters!FromDate.Value)
Thought I would post this here for two reasons
Theories as to why
It might help someone in the future
Your original parameters take Now and subtract the minutes to arrive at a 15-minutes time, then they take the seconds of another Now (which is later and could be in the next second or even minute) and subtract that value to arrive at a 0-second time (or a 59-second time). This could already cause a problem when there is a change of seconds between the first and the second Now, which isn't very unikely, as on my test system there were 0.59 seconds between the two evaluations of Now in the FromDate parameter. Also, the Now value is more accurate than just a second, and your formula does not respect that. Therefore, if the records you are trying to process in your report happen to have a time of exactly a quarter of an hour, the first parameter is for sure greater (by maybe 0.01 second) and so the record is ignored.
Your formula for the "new parameters" does not depend on the seconds of Now() and will always return a time with no fraction of a second, so I guess that that's what makes the difference.
The expression for the FromDate could be simplified a little:
=Today.AddSeconds(900*(DateDiff(DateInterval.Minute, Today, Now)\15-1))
If you do not plan to run the report very short before midnight, there should not be a problem caused by a change of the day during the evaluation of Today and Now, and you could calculate the second parameter in a similar way, independently from the first one:
=Today.AddSeconds(900*(DateDiff(DateInterval.Minute, Today, Now)\15)-1)
The original parameter values were being calculated individually which means they would each have slightly different values for Now(). I know this is a long shot, but it's a theory. If the subscription job fired off a fraction of a second before a 15 minute interval, it's possible that the ToDate returned just before the FromDate. This would result in an invalid date range.
With the new expressions, the ToDate is referencing the FromDate which forces them to be calculated in sequence, not in parallel. Not to mention you're adding to the FromDate which also forces the date range to have a consistent length. However, you may still run into a case where you get the same report twice if the FromDate is calculated on the wrong side of a 15 minute cutoff.
One way to test/avoid this issue would be to offset the subscription time so that it doesn't actually try to fire at the exact 15 minute cutoffs. For example, you could have it scheduled to go off 1 minute afterwards.

Adding two date stamps into a single SSRS expression/cell

This is all done in Microsoft SQL Server Report Builder
So I have a large data set that contains Work orders and then their 'type/craft'. Each craft is then broken down into each row so that you can see how many work orders are still open in the certain craft. At the top of the page, It list, WO's 1-2 Past Due, WO's 3-5 Past Due, WO's 6-10 Past Due... etc, till you reach 30 days+
I then have an expression inserted that will tell you what date the 1-2 days is... However, I am having trouble making the expression value be 2 dates or an in between date.... For example, I have =DateAdd("d", -1, Now) inserted which will give me the date from 1 day back, however, I would ALSO like it to show 2 days back.... So instead of ONLY saying 6/13/2018... it would say 6/12/2018 to 6/13/2018
I guess I could go back and edit my SQL code to automatically do the dates, however I thought it would be easier to use the report system.
You would want your expression to be something like this:
=DateAdd("d", -2, Today()) & " to " & DateAdd("d", -1, Today())
If you need the time as well you would want to use Now instead of Today, but based on your question it seems you are only interested in the dates, so this should return exactly what you are looking for.

FROM_DAYS() not giving expected output[MySQL]

The official documentation says that FROM_DAYS returns a valid date given number of days N.
Then why is this happening ?
Should it not display the valid dates for days less than a year, like
from_days(5) = 0000-01-05 ?
Edit : I was solving a question which went as "Find the period an employee has worked given their date of joining and report the duration in the format years,months,days"
And I was using the following query :
select Emp_Name,
date_format(from_days(datediff(curdate(),Date_of_Join)),"%y") as year,
date_format(from_days(datediff(curdate(),Date_of_Join)),"%m") as month,
date_format(from_days(datediff(curdate(),Date_of_Join)),"%d") as day
from EMPLOYEE;
It was in these results that I discovered this discrepancy.
As the MySql manual reports:
The function is not designed for use with dates before the advent of
the Gregorian calendar in October 1582. Results will not be reliable
since it doesn't account for the lost days when the calendar changed
from the Julian calendar.
So, if you set the argument of this function with a small number (around N < 1582*365), it is not reliable.