Edit Widget Script Sisense to display NA for specific condition - json

I want to add a custom script for my widget using this option
I have a calendar filter on my dashboard like below
It is being carried forward to the widget like so
Our fiscal year is Oct to September.
Now, my requirement is that whenever user selects date range spanning more than 1 fiscal year(eg. 1st September 2021 to 30th October 2021), the widget (gauge indicator) should display NA for both value and secondary measure.
Earlier, my secondary measure was empty, so I just added a measure there to count unique number of fiscal years and added the below code in widget script.
widget.on('render', function (se, args) {
if(se.queryResult.secondary.data > 1)
{
se.queryResult.value.text = "N/A";
}
});
But now, I have another measure in the secondary field so cannot do this anymore. For this, I was thinking of adding this condition in the widget script by somehow using the values from the date filter. I've searched the sisense documentation but am unable to find ways on how to access the filter values selected by user.
Please help me with the script for this.

Related

Auto populate dates of the week Paginated reports

Good day
I am very very new two paginated reports so forgive me if this is a silly question
I have a report that displays values for Mondays to Fridays based on the date selected from a date picker.
So basically
You select a date (Example 24 Nov) and the following table is displayed based on values pulled from SQL.
Now my question is how do I display the dates of the weekdays too?
So if the date selected is Thursday 24 Nov, in the column headers under the week day names it should give the corresponding date i.e Monday-21/11/2022, Tuesday - 22/11/2022, etc.
Below is a little snippet of the data
So the date picker is based on the ReportingDate column. The rows of the matrix consist of Region and Country and the values are the sum of Monday-Friday.
Any guidance would be greatly appreciated.
Edit: The day names are not obtained via an expression in SSRS. They carry over from the column headers in the data set.
Assuming you have some expression to get the actual day name already, you can leave that bit as it is.
Now, double click the column header "cell"/textbox to get a cursor in there, then click at the end of the existing fields/expression.
Now just put a space in and then right-click and choose "Create Placeholder". The placeholder dialog will appear.
This placeholder acts almost like a separate textbox to you can put whatever you want in there, click the '[fc]' button next to the Value property and then set this to whatever you want, e.g. =Fields!ReportingDate.Value.
Now go to the "number" tab on the same dialog box and set the format to the required date format.
If you want to edit this later, just double click the cell again but this time right-click the placeholder and choose properties.
The other way of doing this would be to add another row to your header and set that to be the date instead but then you have to mess around removing borders etc., sometimes this can be easier if layout is an issue but you have a couple of options at least now.
I managed to figure it out with the help of the following post.
These are the steps I followed
Get the date of the first day of the current week (Sunday's date) using the formula explained in the link
DateAdd("d",1- DatePart("w", CDate(Parameters!ReportingDate.Value)), CDate(Parameters!ReportingDate.Value))
Use DateAdd to add the corresponding number of days to get to a required weekday. That is for Monday add 1, Tuesday add 2,...
DateAdd("d",1,DateAdd("d",1- DatePart("w", CDate(Parameters!ReportingDate.Value)), CDate(Parameters!ReportingDate.Value)))
Format datetime to date and add new line to insert date below day name
="Monday" + Environment.NewLine + FormatDateTime(DateAdd("d",1,DateAdd("d",1- DatePart("w", CDate(Parameters!ReportingDate.Value)), CDate(Parameters!ReportingDate.Value))), DateFormat.ShortDate)

How to define Row Data group in SSRS if we have two parameters to be considered?

Im new to SSRS reporting. Im trying to edit in *.rdl file, where it has row data grouping to view data for a month.
eg: =Fields!EndOfMonth.Value
Here EndofMonth will return September 30th /October 31st etc. So table is grouped by one month data.
I need to edit this for a custom data range.
eg: startdate='2019-09-05', enddate='2019-10-12'
So, report table should display rows between September 5th to October 12th.
I have both startdate enddate parameters defined in the *.rdl file.
But I dont know, how i can switch between both date ranges based on condition. that is , if companyid<>50 pick custom range else standard.
eg:
I defined like this, but here i could point only one parameter(i used enddate only).So report shows rows between October 1st to 12th only.
How can I modify the condition?
=IIF(Parameters!CompanyId.Value<>50,Fields!EndofMonth.Value, Parameters!EndDate.Value)
EDIT
I have 2 datasets defined to switch between companyids.
I modified above condition based on Nicks answer, but i get lookup function can not be used with functions issue.
I tried following both way, but getting same rows again and again
=IIF(Parameters!CompanyId.Value<>50,Fields!EndofMonth.Value,
IIF(Lookup(Fields!TankDateCombo.Value, Fields!TankDateCombo.Value,Fields!Date.Value,"Dataset2")
>= Parameters!StartDate.Value,Fields!EndofMonth.Value,
Parameters!EndDate.Value))
=IIF(Parameters!CompanyId.Value<>67,Fields!EOM.Value,
IIF(Day(Lookup(Fields!TankDateCombo.Value, Fields!TankDateCombo.Value,Fields!Date.Value,"OESNeoData"))
>= Day(Parameters!StartDate.Value), Fields!EOM.Value,
Parameters!EndDate.Value))
MY dataset contains following data;
I fixed this by simply deleting that row group and passing start/end dates for both datasets

SSRS: Filter 1 field based on 2 possible values in another field

I don't if I'm being a knucklehead, but I've searched considerably and tried several options: can't make it happen. Here is the issue.
I have the following Data Query:
First of all, sorry it's French. Secondly, as you see, the fields are "File number", the "Year" and the "Number of distinct patients".
Wanted result: I want to filter for Case numbers who appear both at 2015 and 2016.
As you see, certain patients showed up several years in a row. However, I want to find out how many showed up in 2015 AND 2016 only (not 2014, etc.) (so a total of 2 visits for the 2 years combined). So solely filtering in my Data Query on 2015 and 2016, doesn't do the job, since it fails to exclude the patients that only showed up once. Furthermore, filtering on 2015 and 2016, and then Count(Fields!File_number.Value)=2 wouldn't work since it fails to exclude the patients that might have been here in 2014.
I have tried several Boolean expressions, but as soon as I include 2 years in my filter, it blanks my tablix out. (Understandibly cause I tell it that Fields!Year.Value must be equal to 2015 and 2016 simultaneously).
So I tried bypassing it by telling it that and did the following:
Expression:
=IIF(Lookup(Fields!FileNumber.Value, Fields!FileNumber.Value, Fields!Year.Value, "Dataset")=2015 AND Lookup(Fields!FileNumber.Value, Fields!FileNumber.Value, Fields!Year.Value, "Dataset")=2016, True, False)
It works for 1 year only: as soon as I add 2015 either by and "AND" or by adding an additionnal filter, mytable goes blank.
Any suggestions? Thanks!
Yeah, this isn't an easy thing to solve, you aren't being a knucklehead :) You are correct about the double boolean expressions in the query and the two combined lookups won't work either. In the case of a lookup, LOOKUP returns the first match in a dataset, so every time, both of those looksups are going to return the first value.
There is another function called LookupSet which does return ALL matches from a query though. It should be possible to create an ugly expression around this function to test specifically whether the string 2015 and 2016 both appear in the results with something like:
=Join(LookupSet(Fields!FileNumber.Value, Fields!FileNumber.Value, Fields!Year.Value, "Dataset"),",")
and then substring searching for both "2015" and "2016" (I'll let you fiddle with that part)

Graph - just show last 12 months

I have a line graph in my report.
My report has no parameters on it.
What I ideally want it to do is if I run the report today (May) it will only show me the last 12 months so May to May.
At the moment it is including April from last year as well, so would want that excluded. If I run it in two months time in July I would want it to only show July to July.
Hi,
The key here is the DatePaid field. This is the date that drives the graph.
The graph gets the Financial Year and Month from a date table.
The plots on the graph use an expression -
[code="other"]=SUM(IIF(Fields!InvoicePaid_.Value = "Yes" And Fields!PaidTarget.Value = "InTarget",1, 0))/Count(IIF(Fields!InvoicePaid_.Value = "Yes", 1, Nothing))[/code]
This allows a % to be calculated on the graph series you see above, to just show invoices that have been paid and are in target.
The report uses TSQL and I'm wondering if there is a flag I can place against any invoice that was paid 12 months ago. And then via a filter remove them from the graph?
So today date is 02/06/2015. I would want to mark all invoices with a flag upto 01/06/14 so they all appear on the graph - but May and April 2014 would be excluded.
Then when I run the report next month say - 7th of July 2015 - June 2014 will no longer appear on the graph but the 01/07/2014 and onwards would?
Hope that makes sense.

Add Datetime rows to a datatable in the DataTableBuilder for Google Scripts

I've built an intraday macroeconomic forecast system in R. It uses intraday market data to update an forecast. Basically, I have a forecast series that looks like financial market data.
I want to show these data using a Google Chart in the Google App Script platform. To keep the datatable small (and thus load time down), I only want to plot intraday values for the five most recent days. For older days, I want to save only the last forecast of the day. That is, I want to have a time series plot with two frequencies of data which the user can choose from.
Here's and example of how I write the data from R (columns separated with "|"):
OBSlatest.forecast|freq
2014-03-10 14:45:00 EDT|4.09662|D
2014-03-11 15:00:00 EDT|4.10075|D
2014-03-12 14:57:00 EDT|4.08862|D
2014-03-13 14:57:00 EDT|3.998|D
2014-03-14 15:00:00 EDT|3.9843|D
2014-03-10 09:30:00 EDT|4.13823|I
2014-03-10 09:33:00 EDT|4.13468|I
2014-03-10 09:36:00 EDT|4.14078|I
I'm currently translating this table into Google App Script with
var data = Charts.newDataTable()
// Set data table columns
.addColumn(Charts.ColumnType.DATE, "Time")
.addColumn(Charts.ColumnType.NUMBER, "Forecast")
.addColumn(Charts.ColumnType.STRING, "Frequency")
// Fill in rows
.addRow([new Date(2014,3,13,14,57, 0),3.998 ,'D'])
.addRow([new Date(2014,3,10,9,30, 0),4.13823 ,'I'])
// More rows, but they all look like this, either a 'D' or 'I' at end
I've got a rough script up now that uses a category filter so that the user can choose to show either the daily frequency 'D' or intraday frequency data. However, I seem to be using the Date() function wrong. My data are all out of order and the dates don't match what I've loaded. My understanding the of Date() function's arguments is: Date(year, month,day,hour,min,sec), yet I only seem to be able to get the year to show up right in my chart. For example, the first row I'm adding in my code above yields "13 apr 2014 11:57:00" when my expectation is that it'd give "13 mar 2014 13:30:00"!
Nearest I can tell is that it is subtracting three hours from my time and one month from my month. Any ideas what's going on? This approach works fine for an HTML implementation of Google Charts, which I have up at: EfficientForecast.com
Thanks for any help!
The month parameter is zero-based, so subtracting one is the correct/expected thing to do. Check the MDN docs.
About your hour issue, I can not reproduce it. So I imagine it is something specific to your system. Please check what your Google Drive timezone setting is, then this Apps Script's setting and lastly your OS timezone setting. I imagine this is happening because some of these configurations are not matching.