I have some basic strings:
month
3
4
8
11
12
I want to output month names as well as them being sortable by month (not alphabetical):
March
April
August
November
December
Is there a simple way to do this without doing multiple if's?
(Which doesn't allow you to sort by month)
ifelse({month}=1,"Jan",
ifelse({month}=2,"Feb",
ifelse({month}=3, "Mar",
ifelse({month}=4, "Apr",
ifelse({month}=5, "May",
ifelse({month}=6, "Jun",
ifelse({month}=7, "Jul",
ifelse({month}=8, "Aug",
ifelse({month}=9, "Sep",
ifelse({month}=10, "Oct",
ifelse({month}=11, "Nov",
ifelse({month}=12, "Dec",
"Error"))))))))))))
We could make use of left() and formatDate() functions.
Ex: left(formatDate({datefield},'MMM-dd-yyyy'),3)
Suppose if we are dealing with strings, we could make use of parseDate() to convert it into Date datatype and then make use of left() and formatDate() functions.
Here is the documentation for the above-mentioned functions:
formatDate() - https://docs.aws.amazon.com/quicksight/latest/user/formatDate-function.html
left() - https://docs.aws.amazon.com/quicksight/latest/user/left-function.html
parseDate() - https://docs.aws.amazon.com/quicksight/latest/user/parseDate-function.html
If your data has a column which is date (object) as your source then you can add a new calculation column that formats the date as 3 letter abbreviation.
If your data is only strings add a new calculation column that uses the string to calculate an actual date.
Sort the table on the date column and just hide that column if you like....This should display just the months in the correct order.
I think parseDate() is the function you want to use to do this.
https://docs.aws.amazon.com/quicksight/latest/user/parseDate-function.html
Related
In my db i have a column created_at (date_time format). I would like to create an analytical dashboard when it will be possible to filter data by create_at by giving month name (one or more - multiple choice)
I have added a new calculated field "month" in data set with following formula:
formatDate(truncDate("MM",{created_at}),"MM" )
As a result i get new column with strings like "01", "02" etc.
I've created a new parameter:
name: Month
Data type: string
Values: multiple values: {01, 02, 03 ....}
I've created a new control:
name: Month
Style: Multi select drop down
Values: Link to a data set field -> Data set -> Month column
I've created a new filter for Month columns, based on Month parameter
My problem is: how to achieve the same result (filtering by month, multi select) having month names displayed in the control, not "01", "02" etc. Is it possible?
UPDATE
It is much better to have following formula in Month calculated field:
extract("MM",{create_at})
But it does not solve my problem....
What i did, but i really don't like this solution as it is so ugly.....Any better solution is welcome :)
new calculated field month_number, with formula:
extract("MM",{create_at})
new calculated field month_name with formula:
ifelse({Month_number}=1,"Jan",ifelse({Month_number}=2,"Feb",ifelse({Month_number}=3, "Mar",ifelse({Month_number}=4, "Apr",ifelse({Month_number}=5, "May",ifelse({Month_number}=6, "Jun",ifelse({Month_number}=7, "Jul",ifelse({Month_number}=8, "Aug",ifelse({Month_number}=9, "Sep",ifelse({Month_number}=10, "Oct",ifelse({Month_number}=11, "Nov",ifelse({Month_number}=12, "Dec","Error"))))))))))))
I'm desperately trying to understand swift's DatePicker. I have a need to select dates from Julian Day 0 (11/24/4714 BCE) to dates in the future. When I extract the DateComponents from the DatePicker, they do not appear to be a 'proleptic' gregorian calendar. For instance, by selecting 3/1/300 AD (or CE), the month and day are 2/29. This seems consistent with the Julian Calendar, a date I cannot select with the DatePicker's calendar set to iso8601 or gregorian. I am familiar with the date of adoption of the Gregorian calendar, and indeed this is where the discrepancies begin. But why won't it calculate the proleptic dates, or am I misunderstanding this. Extracting these components is necessary for calculating various quantities such as Julian Day or converting from one calendar to another. Even a suggestion of where to find the info would be appreciated.
---Edited to show code -----
#IBAction func calculate(_ sender: Any) {
var mycal = Calendar(identifier: .iso8601)
//var mycal = Calendar(identifier: .gregorian)
let picked_date:Date = datePicker.dateValue
let formatter1 = DateFormatter()
formatter1.locale = Locale(identifier: "en_US_POSIX")
formatter1.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let picked_format = formatter1.string(from: picked_date)
//print("picked_format: \(picked_format)")
let format_date = formatter1.date(from: picked_format)
var tz: String { return TimeZone.current.identifier }
let myzone = UTC.state == NSOnState ? tz : "GMT"
//let era = AD.state == NSOnState ? 1 : 0
mycal.timeZone = TimeZone(identifier: myzone)!
var comps = mycal.dateComponents([.year,
.month,
.day,
.hour,
.minute,
.second,
//.era,
//.nanosecond,
.timeZone],
from: format_date!)
print(comps.month!)
print(comps.day!)
Bottom line: The discrepancies in what was shown in DatePicker vs the 'elements' of the date object it produced (namely, YEAR, MONTH and DAY) were due wholly to a careless mistake I made writing the code: The failure to ensure that all the objects that dealt with dates were specified to the same Calendar. Initially, my DateFormatter and DateComponents objects were set to ".iso8601" and failing to specify a calendar for the DatePicker defaulted it to my locale, which meant ".gregorian". This produced a 10 day discrepancy in the date prior to Oct 15, 1582. Also: A DatePicker using the Gregorian calendar will allow you to select days from 5 Oct 1582 - 14 Oct 1582 (inclusive), just as I would expect from a proleptic calendar. A DatePicker using the ISO calendar will NOT allow dates in this range. Stepping down from 15 Oct 1582 by one day will result in the DatePicker showing 4 Oct 1582 ... not the result I would expect if it is based on the proleptic Gregorian.
Some caveats, though. Apple's documentation and the ISO standard itself lead me to believe that the ISO calendar was based on a proleptic Gregorian calendar. This proved to be untrue. You can repeat for yourself the following: Create a DatePicker specifying the ISO calendar and it will allow you to choose dates which do not exist in the Gregorian calendar, namely leap years for such years as 1500, 1400, 1300, 1100, 1000, etc. This is more in keeping with the ISO calendar behaving like the Julian Calendar prior to the adoption date. Indeed, the date discrepancies begin to narrow as the year number decreases because the ISO calendar is counting those years as leap years. The error becomes ZERO from 1 March 200 - 28 Feb 300 AD, exactly as one would expect of a Julian Calendar vs a proleptic Gregorian calendar. I don't know if I am misunderstanding how the ISO calendar is supposed to behave, or if this is a bug. Thanks to Willeke for leading me to the correct solution!
I have several records in my database, the table has a column named "weekday" where I store a weekday like "mon" or "fri". Now from the frontend when a user does search the parameters posted to the server are startday and endDay.
Now I would like to retrieve all records between startDay and endDay. We can assume startDay is "mon" and endDay is "sun". I do not currently know how to do this.
Create another table with the names of the days and their corresponding number. Then you'd just need to join up your current table with the days table by name, and then use the numbers in that table to do your queries.
Not exactly practical, but it is possible to convert sun,mon,tue to numbers using MySQL.
Setup a static year and week number like 201610 for the 10th week of this year, then use a combination of DATE_FORMAT with STR_TO_DATE:
DATE_FORMAT(STR_TO_DATE('201610 mon', '%X%V %a'), '%w')
DATE_FORMAT(STR_TO_DATE('201610 sun', '%X%V %a'), '%w')
DATE_FORMAT(STR_TO_DATE('201610 tue', '%X%V %a'), '%w')
These 3 statements will evaluate to 0,1,2 respectively.
The main thing this is doing is converting the %a format (Sun-Sat) to the %w format (0-6)
well i don't know the architecture of your application as i think storing and querying a week day string is not appropriate, but i can tell you a work around this.
make a helper function which return you an array of weekdays in the range i-e
function getWeekDaysArray($startWeekDay, $endWeekDay) {
returns $daysArray['mon','tue','wed'];
}
$daysRangeArray = getWeekDaysArray('mon', 'wed');
now with this array you can query in table
DB::table('TableName')->whereIn('week_day', $daysRangeArray)->get();
Hope this help
I am attempting to retrieve Google Analytics daily visitor counts. I'm following this blog post.
For under 30 days of consecutive data, everything works great. The problem is that the result rows get "grouped together." Consider this query:
{ ids: 'ga:44339606',
'start-date': '2013-01-01',
'end-date': '2013-02-14',
dimensions: 'ga:day',
metrics: 'ga:visits',
segment: 'gaid::-1' }
The values returned for days 01 -14 are incorrect, because they actually represent the sum of January 1st + February 1st, and the sum of January 2nd and February 2nd, and so on. In other words: there is only one entry returned for each day of the month, 1-30, instead of returning 44 entries.
How can I adjust for this, without breaking the query into multiple calls?
Turns out, I wanted the ga:date dimension instead of ga:day
Check out the playground; it's great for figuring out params: https://ga-dev-tools.appspot.com/explorer/
Date column is created using colmodel below.
This column shows values like 0101.0101.7070 for every date column.
if formatter:date is removed, date is correct.
How to show normal date values with formatter:date ?
{ "name":"Date",
"formatter":"date",
"datefmt":"dd.mm.yyyy",
"formatoptions":{"newformat":"dd.mm.yyyy"},
"editable":true
}
Update.
Data is passed from server using json in same dd.mm.yyyy format like
{"total":2,"page":1,"records":57,"rows":
[{"id":"9279","cell":["9279","42","","10.08.2011","","","","False"]},
{"id":"9278","cell":["9278","41","","12.08.2011","","","","False"]},
...
Using d.m.y formats in column options as suggested shows proper dates but with 2 year digits only..
I'm looking for a 4-digit year numbers. I tried d.m.yyyy format but this shows 8 digit year numbers and 1 for month and day as 01.01.70707070
I also tried to add srcformat: 'dd.mm.yyyy' to formatoptions but this does not change the wrong result.
To display the day as the number you should use j or d. For the displaying month as the number you should use n or m. The d and m includes 0 padding at the beginning if needed. The 'y' means two digit year format and Y means four digit year.
So you probably need srcformat: 'd.m.Y' or srcformat: 'j.n.Y'.
Use d.m.y instead of dd.mm.yy ,