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.
Related
I am trying to calculate the difference in days between 2 data sets and then if the value is between 1 and 2 days then it should show compliant if the value is a negative number or greater than 2 days I want it to show non-compliant. I am not sure what I have wrong, it runs however they all show compliant
Background on the calculation needed.
IMM Discharge compliance - Hospitals must
deliver a copy of the signed notice to each beneficiary not more than two (2) days before the day of discharge. Follow-up notice is not required if delivery of the initial IM falls within two (2)
calendar days of discharge.
FYI - the first IFF statement is because some do not have dates so that was to account for those
=IIF(
IsNothing(Lookup(Fields!Account_Number.Value,Fields!Account_Number.Value,Fields!Intervention_Date_Of_Service.Value, "Interventions")),
"No Intervention",
IIF(
DateDiff("d",Fields!Actual_Discharge_Date.Value,Lookup(Fields!Account_Number.Value,Fields!Account_Number.Value,Fields!Intervention_Date_Of_Service.Value, "Interventions")) <=2,
"Compliant",
"Non-compliant")
)
I have tried multiple variations =1 or 2, etc if I use just the =2 they all show non-compliant
You have two conditions for non-compliance - the difference being negative or greater than 2 days so you have to check both conditions. Try something like this:
=IIF(IsNothing(Lookup(Fields!Account_Number.Value, Fields!Account_Number.Value, Fields!Intervention_Date_Of_Service.Value, "Interventions")),
"No Intervention",
IIF(DateDiff(DateInterval.Day, Fields!Actual_Discharge_Date.Value, Lookup(Fields!Account_Number.Value, Fields!Account_Number.Value, Fields!Intervention_Date_Of_Service.Value, "Interventions")) < 1,
"Non-compliant",
IIF(DateDiff(DateInterval.Day, Fields!Actual_Discharge_Date.Value, Lookup(Fields!Account_Number.Value, Fields!Account_Number.Value, Fields!Intervention_Date_Of_Service.Value, "Interventions")) > 2,
"Non-compliant",
"Compliant"
)
)
)
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");
}
Using a Power Query M function, I am trying to set current month's ending balance to be next month's opening balance. I have tried various different date functions (i.e. Date.IsInPreviousMonth) but cannot get this to work.
The attached image shows what I am trying to accomplish using Power Query M formula.
This is possible with M but is quite complex. Here is a PowerBI Community post that gives options.
I would prefer to use DAX's PREVIOUSMONTH function as opposed to M.
Create a new measure along the lines of:
Previous Month Balance =
CALCULATE(SUM('Fact - Sales'[Cost Price]),
PREVIOUSMONTH('Dimension - Calendar'[Date]))
I am using SSRS 2016 application to pull data from SharePoint list.
My task is to calculate the average DaysUsed and the average Percentage from a column.
It is a Matrix report which has two columns:
Sum(Fields!Days.Value)
Sum(Fields!Percentage.Value)
The task is to show the average days and average percentage.
I have tried the =Avg(Fields!Days.Value) but this shows wrong result.
UPDATE
Yes, the matrix is grouped by the Month to show each relevant month.
See the screenshot below what I have tested so far.
The DaysUsed is a calculated between 2 fields [FromDate] and [UntilDate] by summarising the total days minus the weekends. see below:
=(DateDiff(DateInterval.day,CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")), CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")))+1)
- (DateDiff(DateInterval.WeekOfYear,CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")), CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")))*2)
- IIF(Weekday( CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")),1) = 1,1,0)
- IIF(Weekday( CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")),1) = 7,1,0)
- IIF(Weekday( CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")),1) = 1,1,0)
- IIF(Weekday( CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")),1) = 7,1,0)
Furthermore, the [DaysUsed] row then consists of IIF(value is null then show 0 otherwise show the total value of days used).
=IIF(IsNothing(Sum(Fields!Days.Value)), "0", Sum(Fields!Days.Value) )
Sum(Fields!Days.Value)/CountRows()
Shall give you average days. Similarly goes for others as well.
If you has a field called Fields!Days.Value, I guess your data in the screenshot is already grouped by month. This means the expression
=Avg(Fields!Days.Value)
gives you the average over all Days (sum of all days / count of all days).
If you want to use the grouped values (by mounth) you either can use the following expression when you are inside the scope (the monthly socpe; indicated by the brackets on the most left side on your tablix)
=Sum(Fields!Days.Value) / Count(Fields!Days.Value)
If you are not in the scope you have to tell the tablix that is should use your monthly grouping. For this you can use the following:
=Sum(Fields!Days.Value, "YourMonthGroupName") / Count(Fields!Days.Value, "YourMonthGroupName")
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")