I have multiple items that are traps that return an integer such as below.
app.tidal.Health.HighPriority.MessagesInQueue
app.tidal.Health.CommDefault.MessagesInQueue
app.tidal.Health.Default.MessagesInQueue
I want to create a trigger if two or more of these has returned a value of greater than 0 in the last 3 checks to send a severity High message.
I'm having a hard time trying to devise my trigger this is what I currently have:
{Template_App_Tidal_Masters:app.tidal.Health.CommDefault.MessagesInQueue.min(#3)}>0 and
{Template_App_Tidal_Masters:app.tidal.Health.Default.MessagesInQueue.min(#3)}>0 and
{Template_App_Tidal_Masters:app.tidal.Health.HighPriority.MessagesInQueue.min(#3)}>0
But obviously it won't work as it's an and statement so all 3 would have to be greater than 0 the last 3 checks. Formatted the trigger on 3 lines to make it clearer.
This should work:
({Template_App_Tidal_Masters:app.tidal.Health.CommDefault.MessagesInQueue.min(#3)}>0) +
({Template_App_Tidal_Masters:app.tidal.Health.Default.MessagesInQueue.min(#3)}>0) +
({Template_App_Tidal_Masters:app.tidal.Health.HighPriority.MessagesInQueue.min(#3)}>0) > 1
Each part first evaluates an individual item to be larger than 0. If that is true, that part of the expression evaluates to 1, if false - to 0. In the end we sum up the results of these evaluations (not the original item values) and check whether two or more items had values larger than zero.
Related
I need a table that calculates percentage changes between columns of another table (current value - previous value) / previous value
if a value goes from 0 to anything the result should be 1, otherwise it would cause a division by 0 error.
if the current value is also 0, return 0. otherwise calculate the percentage change
how do I replicate this if block in sql?
if previous value == 0
if current value == 0
return 0
return 1
return (current value - previous value) / previous value
If you want to nest the if statements in an select you can do it like this:
if(condition1, if(condition2, inner_true, inner_false), outer_false)
I don't necessarily claim that's the best solution to your problem compared to other ways to structure the query overall, but it does nest the if statements, as you requested.
If I understand what you meant by your non-select example, I think that would be for your case
select if(previous_value=0, if(current_value=0,0,1), (current_value-previous_value) / previous_value)
Updated: While the solution provided =IF(A2>A1,IF(A2>MAX(A$1:A1),ROW()-1,IFERROR(B1+1,1)),1) does work for the original test data, it doesn't work for a more complex data set, see the second screen shot below:
Original question:
I have a need to process a column (A in the example) of numbers that represents a value changing over time, and establish for how many rows the present row's number has been the largest number, and report that as illustrated in Column B.
What I can't figure out is whether there is a way of producing column B using spreadsheet functions or if I need to write some apps script to do the calculations. I've looked at the usual suspects like MAX() and LARGE() but they don't quite do what I want.
What I want is something like MAXSINCE(A99, A:A98) but that doesn't exist.
Updated data set which still doesn't have an answer for the question: for how many rows has this row had the largest value?
Logic Flow:
Check if current value A2 is greater than previous value A1; If not, return 1
If the above is true, Check whether current value is greater than the present MAX. If so, return current ROW's number - starting offset 1 else add 1 to previous value B1
Code Sample:
B2:
=IF(A2>A1,IF(A2>MAX(A$1:A1),ROW()-1,IFERROR(B1+1,1)),1)
Drag fill down
I am currently implementing some triggers on the tables of my schema, to ensure quality of imported data.
More specifically, one column (let's call it fraction) is supposed to contain only percentages, i.e. values between 0 and 1 but that can sometimes be slightly above 1.
The thing is that in the original datafiles, these values are expressed as percentages, i.e. 80% for 0.8, etc.
Consequently, there is a risk that some users of the database could import data with the wrong order of magnitude, i.e. importing 70 or 80 instead of 0.7 or 0.8.
To prevent this, I have chosen the following criteria : if the mean value of all the rows that the user is trying to import is greater than 2, I want the software to conclude that the user has imported percentages instead of decimal values, and therefore to correct this mistake by dividing all the new values by 100.
The following BEFORE INSERT trigger checks, for each row, whether the value is > 2 or not, and if it is, it divides the value by 100:
CREATE DEFINER=`admin`#`localhost` TRIGGER `myschema`.`percentage_trigger` BEFORE INSERT ON `mytable` FOR EACH ROW
BEGIN
IF NEW.fraction > 2
THEN
SET NEW.fraction = NEW.fraction/100 ;
END IF;
END
but my question is: how to have a criterion that sounds like "the mean of all the new values is > 2" instead of a criterion like "this value is > 2"?
I'm trying to achieve my report displaying a "No Data Available" message if no results are returned in my query.
I am trying to achieve this via an expression against the Row Visibility.
So I have a Tablix that looks like this -
If there is data available then I want the third, fourth and fifth line to show.
If no data exists then I want the first two rows to display.....
In the Row Visibility for the first two rows I have the following -
=iif(CountRows("RentTransactions") = 0, true, false)
In the Row Visibility for the remaining three rows I have the following -
=iif(CountRows("RentTransactions") > 0, true, false)
I have a filter on the Tablix that just limits it to "AccountType" = Water.
When I run the report between 01/06/2016 and 30/06/2016 - I know there are not transaction - so would expect my report to return the first two rows....
It doesn't it returns the bottom ones , with no data in it??
What am I doing wrong?
The DataSet is definitely called RentTransactions
There are a few issues going on here.
CountRows with the dataset name will always return the total number of rows in the entire dataset.
Row Visibility will make the entire row blank, but it will still take up space. This would look bad if there are alternating blank rows.
What you're really trying to do is control what is displayed in each cell. So in each cell you'll want to have an expression that checks whether or not to display a value. For example, for the Description field it would look something like this:
=IIf(Count(Fields!Transaction_Type.Value) > 0, Fields!Description.Value, "")
This expression will work by returning a count of 0 for NULL Transaction Types. You can customize this if needed.
Also make sure that the query is returning rows for dates with no transactions. Otherwise there's no raw data for the report to do anything with in the first place.
I am using SSRS 2008 and trying to calculate the following percentage in my tablix:
sum(Fields!Last14Days_Ct.Value) / countdistinct(Fields!Client.Value)
So Last14Days_Ct can be = 1 or 0. I want to sum all of these integer values. Client field is a VARCHAR, and there can be multiple rows / Client. So what I want to do is to calculate the % of Clients within the last 14 days. In other words, each Client has one field "Last14Days_Ct" = 1 or 0. So I just want to calculate the percentage of clients that happened in last 14 days. Here is the SSRS formula I tried right now:
=iif(countdistinct(Fields!Client.Value)=0,0,sum(Fields!Last14Days_Ct.Value)
/iif(countdistinct(Fields!Client.Value)=0,1,countdistinct(Fields!Client.Value)))
And I grouped that row on Fields!Last14Days_Ct.Value.
But problem is that now when I view it in ReportViewer, it shows 2 rows: when Last14Days_Ct = 1 and 0. I only want the row where it = 1 to appear. But if I apply a filter to that group on = 1, it always shows 100%. How can I properly calculate this value please?
When you leave the filter off, is the calculation displaying correctly? If so, then open group properties for Last14Days_Ct, go to Visibility, and for "When the report is initially run" select "Show or hide based on an expression." Use the expression:
=Fields!Last14Days_Ct.Value = 0
That way, you only view the 1 values, but all the values are still in scope for your report, so the math in your calculation still works.