How can I change the text values in Google Data Studio? - case

I have a field called duration_type that can have the values below and I want to show them in my graphs as the expected_values field:
duration_type
expected_values
weekly
Week
monthly
Month
annual
Year

Make a new expected_values field and create the CASE statement:
CASE
WHEN duration_type = "weekly" THEN "Week"
WHEN duration_type = "monthly" THEN "Month"
WHEN duration_type = "annual" THEN "Year"
END

Related

Group by on Month in Oracle

I want group by the result data of oracle database. And also I got the result but the result is groupped as month start to next month start.
I need group by from month start to month end.
"GROUP BY TO_CHAR(COL_DATE,'MON-YYYY')"
As I am getting data from 01-Feb-2018 to 01-Mar-2018.
Required data from 01-Feb-2018 to 28-Feb-2018.
use the TRUNC function.
the following example shows the number of entries per month
SELECT TRUNC(COL_DATE, 'MONTH') AS MONTH, COUNT(*)
FROM TABLE
GROUP BY TRUNC(COL_DATE, 'MONTH');

tsibble with 2 keys (not hierarchy) having the week of the year as index

Can anyone give some suggestions as to how to construct a tsibble?
I have a dateset that has four original columns: product, market, price, date
I want to construct a tsibble object.
I have the key=id(product,market) and 'year of the week' as index.
then I can predict for each product in each market what should be the base line of price.
if you use nycflights13::weather data set, I can use key=id(origin,year) (here I do not have a market so use year to represent the market).
then have idex=week(year+month+day). I can then combine the year, month, day column as date then calculate the week() then add year and week together as 'weekyear' and set up this as an index, then use median(temp) for that yearweek.
After this dataset reform I can have a tsibble able to predict next 2-4 weeks temp.
Looks like you want to convert the date variable to yearweek class first. Can you do
library(tsibble)
data %>%
mutate(index = yearweek(date)) %>%
as_tsibble(key = id(product, market), index = index)

How to add a separate column to data frame with lubridate? Would like to have numerical month and word month in the data frame?

The lubridate allows us to break down y-m-d format to month, year week, etc... I have done this with my data set. I have the months in numerical months, but want a separate column with month abbreviations. I can convert them, but I want to have both numerical and word month in the data frame. Is there another way to go about doing this besides manually adding a column vector?
lubridate::month generates the numerical month. Adding the argument label = TRUE generates the month abbreviation. You can use dplyr::mutate to add the new column.
For example:
library(dplyr)
library(lubridate)
data.frame(Date = as_date("2001-10-11")) %>%
mutate(Month = month(Date),
MonthAbb = month(Date, label = TRUE))
Date Month MonthAbb
1 2001-10-11 10 Oct

show only weekday from date

I'm trying to use a date value I have in my table to show the start date of a holiday as the day value (Monday, Tuesday etc) how would be the best way to go about getting the start day value in this format in VB.NET?
I'm currently working with the date format dd/mm/yy.
Use Weekday and WeekdayName functions
WeekdayName(Weekday(startDate))
Weekday , which returns a number that indicates the day of the week of a particular date. It considers the ordinal value of the first day of the week to be one.
WeekdayName , which returns the name of the week in the current culture that corresponds to a particular weekday number.

Calendar not displaying all stored dates

I am using an ASP calendar to show a list of dates, however the way the calendar overlaps and may show the last few dates of March, with the entire month of April, with the first few days of may(please see images below) is causing a problem.
I have set the 'startDate' and 'endDate' to be the start and end of that month. So if the user clicks 10th April, it will show all the stored dates btn 1st april to the 30th april. I need to change this to include the month b4 and the month after, SO any date in april will include all of March, April and May.
'Green is the date selected by the user, red is todays date, and blue are the stored dates in the DB table.'
DateTime startOfMonth = new DateTime(DiaryDate.Year, DiaryDate.Month, 1);
DateTime endOfMonth = startOfMonth.AddMonths(1).AddDays(-1);
The above code selects the first and last date of each month (of the chosen date)
I want to select the entire previous current and next month
not sure on the correct syntax. any help appreciated?
Try this:
// First, get the dates a month before - and after - the specified date.
DateTime nextMonth = DiaryDate.AddMonths(1);
DateTime lastMonth = DiaryDate.AddMonths(-1);
// Get the last day of next month.
DateTime endOfNextMonth = new DateTime(nextMonth.Year, nextMonth.Month,
DateTime.DaysInMonth(nextMonth.Year, nextMonth.Month));
// Get the first day of last month.
DateTime startOfLastMonth = new DateTime(lastMonth.Year, lastMonth.Month, 1);
Now you can simply use endOfNextMonth and startOfLastMonth as your "boundary" dates, as you are currently doing with startOfMonth and endOfMonth.

Resources