User facing date field granularity control - amazon-quicksight

I'm trying to give my users the option to select the date field granularity of their choice, such as day, week, month or year. This is normally controlled on each graph in the menu show below but this isn't available in a published dashboard:
My first idea was to create a calculated field that truncates my desired date based on a parameter that I expose through a control. This would like something like this, truncDate(${intervalParameter}, {dateColumn}). The problem with this is that the first argument of the truncDate function must one of valid string literals and will throw an error before saving if it isn't.
Does anyone know of any other ways of achieving this? Or maybe some sneaky way of getting around the error?

I figured out a work around using ifElse.
ifElse(
${intervalParameter} = 'Day', truncDate("DD", {dateColumn}),
${intervalParameter} = 'Week', truncDate("WK", {dateColumn}),
${intervalParameter} = 'Month', truncDate("MM", {dateColumn}),
truncDate("DD", {dateColumn})
)
There might be better solutions out there but this is what I've come up with.

Related

Report Builder Expressions

Im new to Report Builder and having issues with some expressions that Im trying to implement in a report. I got the standard ones to work however as soon as I try any distinctions, I get error messages. Over the last couple weeks, Ive tried many combinations, read the expression help, google and looking at other questions at internet sites. To reduce my frustrations, I even would jump to other expressions and walk away hoping I would have different insight coming back.
Its probably something simple or something I dont know about writing expressions.
Im hoping that someone can help with these expressions; they are the versions I get the least errors with(usually just expression expected) and show what Im trying to accomplish.
=IIF((Fields!RECORDFLAG.Value)='D',COUNTDISTINCT(Fields!TICKETNUM.Value),0)
=IIF((Fields!TRANSTYPE.Value)='1' and (Fields!RECORDFLAG.VALUE)='A' or
'B',SUM(Fields!DOLLARS.Value),0)
=IIF((Fields!TRANSTYPE.Value)='1' and
(Fields!RECORDFLAG.VALUE)='P',SUM(Fields!DOLLARS.Value),0)
=Sum([DOLLARS] case when [RECORDFLAG]='P' then -1*[DOLLARS])
Thank You.
=IIF((Fields!RECORDFLAG.Value)=”D”,COUNTDISTINCT(Fields!TICK‌​ETNUM.Value))
The error message gives you the answer here - no false part of the iif() has been specified. Use =IIF((Fields!RECORDFLAG.Value)=”D”,COUNTDISTINCT(Fields!TICK‌​ETNUM.Value), 0)
=IIF((Fields!TRANSTYPE.Value)="1" and (Fields!RECORDFLAG.VALUE)="A" or "B",SUM(Fields!DOLLARS.Value),0)
This is not how an OR works in SSRS. Use:
=IIF((Fields!TRANSTYPE.Value)="1" and (Fields!RECORDFLAG.VALUE="A" or Fields!RECORDFLAG.Value = "B"),SUM(Fields!DOLLARS.Value),0)
The 0s are returned due to your report design. countdistinct() is an aggregate function - it's meant to be used on a set of data. However, your iif() is only testing on a per row basis - you're basically saying "if the current row is thing, count all the distinct values" which doesn't make sense. There are a couple of ways forward:
You can count the number of times a certain value occurs in a given condition using a sum(). This is not the same as the countdistinct(), but if you use =sum(iif(Fields!RECORDFLAG.Value = "D", 1, 0)) then you will get the number of times RECORDFLAG is D in that set. Note: this requires the data to be aggregated (so in SSRS, grouped in a tablix).
You can use custom code to count distinct values in a set. See https://itsalocke.com/aggregate-on-a-lookup-in-ssrs/. You can apply this even if you have only one dataset - just reference the same one twice.
You can change the way your report works. You can group on Fields!RECORDFLAG.Value and filter the group to where Fields!RECORDFLAG.Value = "D". Then in your textbox, use =countdistinct(Fields!TICKETNUM.Value) to get the distinct values for TICKETNUM when RECORDFLAG is D.

switch and/or iff function in SSRS. How to use both or any for two given columns

How to use =SWITCH & IIF condition to change color in SSRS if the condition is met. I have two columns “ScheduledDate” (which is date/time), and Activity(which is text format). I want to change the color of Activity (which has the output as Complete, Current, Overdue), if the ScheduledDate is greater than today’s date, then I want to change the Overdue data in Column Activity to RED.
Should using Switch would be good or IIF. How? Can anyone please give an example?
Appreciate any help on this one.
Thanks,
Niki
In this scenario, if you only need set RED without setting multiple color for fields, it's better to use IIF(). Base on your condition, try the expression below:
=IIF(Fields!ScheduleDate.Value>Now() and Fields!Activity.Value="Overdue",Red,Black)
I think I figured it out. It works. Thanks for your help.
=iif(Fields!ScheduleDate.Value > Now() and Fields!Activity.Value ="Cancelled","Red",
iif(Fields!ScheduleDate.Value < Now() and Fields!Activity.Value ="Created","Green","Red"))

Possible to have a simple formula within the [value_if] argument? - excel

I'm trying to use a relatively basic IF function but having no luck - i'm sure i just have brackets or parenthesis wrong or something. Reckon it will be childsplay for you guys....
The formula is intended to show how many days a date has passed by. Date is shown in T column.
Basically it was working fine as the following, both for pending and past dates:
=IF(T7<=TODAY(), (TODAY()-T7),-(T7-TODAY()))
But I got greedy and wanted it to return more of a statement when the date has passed, as to how much it has passed by. So I've tried to make this happen with:
=IF(T7<=TODAY(),"EffOut(TODAY()-T7) days ago",-(T7-TODAY()))
Hoping it would enter "EffOut 8 days ago" (when TODAY()-T7 is 8 days) for example.
But it doesnt - it shows the entire argument i.e "EffOut(TODAY()-T7) days ago" in the return cell.
Is it possible to have a kind of embedded formula in the 'value_if' fields, mixed with text in this sense?
Happy to share the document if that would help, but will need to clear the data first so just let me know.
Thanks in advance, any help is much appreciated! Having read other posts I think it will just be a simple fix but its well beyond me! (I only got this far by perusing forums...)
Maybe something like this...
=IF(T7<=TODAY(),"EffOut "&DAYS(TODAY(),T7)&" days ago",-(T7-TODAY()))
=IF(T7<=TODAY(),"EffOut "&(TODAY()-T7)&" days ago",-(T7-TODAY()))
You just need to be careful to put "" around any strings. This is how Excel knows that's not a part of the formula. Remember to out the spaces is to the string like I did above so it looks like a sentence. The & sign combines the results of the calculated parts and the strings.

Changing the timezone strings of date_lang.php

CodeIgniter stores timezones for its date class in
system/language/english/date_lang.php
I would like to change the strings in this file so that
$lang['UM12'] = '(UTC -12:00) Baker/Howland Island';
$lang['UM11'] = '(UTC -11:00) Samoa Time Zone, Niue';
would instead be
$lang['-12:00'] = '(UTC -12:00) Baker/Howland Island';
$lang['-11:00'] = '(UTC -11:00) Samoa Time Zone, Niue';
Is this possible at all?
Any change I make to the UM__ portion of one line makes it show as a blank on the dropdown. The remaining (unchanged) lines appear OK.
I have also tried to clone this file to application/language/english/ with similar bad results.
Any insights on this?
It looks like this would require hacks to the date_helper.php file which I am not willing to do.
Instead, the date class in CI has the timezones() function which allows you to convert from, for example, UM5 to -5. In that case one can wrap this function around the U__ value coming from the view/dropdown -- and then save it to DB as -5 or some other INT.
Since I want to show the user their selected timezone on that same dropdown, I am forced to have DB fields for the U__ and INT timezone formats. As far as I know, there is no CI function to convert from -5 to UM5.
So, for the user, I pull the U__ format into the view to autopopulate the dropdown.
For timezone conversions and such, I use the INT format.

JQuery function or functions for dates

I building a custom user control in asp.net where the user can enter in a date. I am already using a JQuery function that puts in a date mask in the format of dd/mm/yyyy, but I am unable to find another JQuery function(s) or one that combines all my needs.
What I am also looking for is:
1) To validate whether the date is really a date, i.e. not 31/13/2010 or anything along those lines.
2) Where I can check to see whether a date is in the past or in future based upon a configuration entry in the application.
Can anyone help me, please?
This is just off the top of my head, but you could use JavaScript's Date object http://www.w3schools.com/jsref/jsref_obj_date.asp
1) You could use one of the following
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Then verify that the date components are the same as entered. If you set the month to 50, it will take the year, and go 50 months forward... which seems odd, but... Just have to verify the information is what you entered. The months start at 0 for January, so when checking, be aware of that.
2) There's probably a lot of ways to do this check, but a quick thought on it is
var t = d.getTime() - new Date().getTime();
If t is positive, it's in the future, if it's negative it's in the past.
The new Date() creates a date object with the current time.
You could also use the jQuery UI DatePicker. http://jqueryui.com/demos/datepicker/
I haven't checking into the exact functionality it has that might fit your requirement, but it is another resource to check into.
HTH

Resources