Tableau Using Parameters for a Date Selector - date

I've been looking into making a date selector so instead of filtering by Month, Week by adding filters then displaying the quick filters to correspond. I want to be able to dynamically change the date so I can choose between Quarter, Month and Week in a single drop down.
I have made the selector part no problem it shows but when I come to my calculated field, it's not behaving how I would like.
Here is my calculated field:
CASE [Parameters].[Date Select]
WHEN 'Quarter' THEN QUARTER([Date])
WHEN 'Month' THEN MONTH([Date])
WHEN 'Week' THEN WEEK([Date])
END
This gives 2 errors...
Unknown Function QUARTER called
Unknown Function WEEK called
I am puzzled because the month one is fine.
Normally in tableau to get the month/quarter/week, I click on the Date dimension and select Month or week and it filters and displays like so: MONTH(Date).
Can anyone tell me where I'm going wrong and how I can pull the week and quarter from date in the calculated field so my selector will work.
Thanks.

There are no QUARTER and WEEK functions in Tableau, as you can see in the image below.
What you should be using to get these values are:
DATEPART('quarter',[Date])
DATEPART('week',[Date])
For filtering the date using your parameter as filter, I'll assume that you want to filter the current quarter, month or week. In this case you'll need to setup your paramaters like this:
Then you'll create a Calculated Field with the following formula:
DATEPART([Date Selector],[Date]) = DATEPART([Date Selector],TODAY())
This should give you a True/False dimension which you will use as filter for the value True. After that you should have a working parameter filtering your data accordingly to the value set.

Related

Difference between previous and current month

I'm trying to calculate the difference between current month and previous month.
The date field in my DB called C_DATE (dd/MM/YYYY), and I'm using in my sheet a date filter in the format: Year(C_DATE)&'-'& Num( Month(C_DATE),'00'). So when the user choose month (for example 2022-05), he will see the difference in the data between May and April.
I've already tried to calculate by:
count ({<Answer_num={">=6"}, C_DATE={">=$(=(MonthStart(Max(C_DATE))))<=$(=(MonthEnd(Max(C_DATE))))"}>}Answer_num) -
count ({<Answer_num={">=6"}, C_DATE={">=$(=(AddMonths( MonthStart(Max(C_DATE)),-1)))<=$(=(MonthStart(Max(C_DATE)))))"}>}Answer_num)
but i'm getting wrong outcome. is it maybe because of the date filter format? What can I do?
Thank you!
I think this is a matter of getting the date format correct and using the proper set operator. This may work:
=Count({1<Answer_num={">=6"}, C_DATE={">=$(=Date(MonthStart(Max(C_DATE)), 'DD/MM/YYYY'))<=$(=Date(MonthEnd(Max(C_DATE)), 'DD/MM/YYYY'))"}>*$} Answer_num)
-
Count({1<Answer_num={">=6"}, C_DATE={">=$(=Date(AddMonths(MonthStart(Max(C_DATE)),-1), 'DD/MM/YYYY'))<=$(=Date(MonthStart(Max(C_DATE)), 'DD/MM/YYYY'))"}>*$} Answer_num)
This adds the =Date(..., 'DD/MM/YYYY') expression to the set expressions so that the formatting matches the format of the [C_DATE] field. We also add the * set operator so that we get the intersection between the selection ($) and our ">=...<=..." set expression.
I'm sort of guess on the use of the intersection operator, it could be that the union operator (+) is the correct one to use in this case.

DAX and FORMAT function

i have a field for date with date, month and year.In my visualization, I need date to be displayed in (MON-Year) format.
I switched to data view, created calculated column with
Mon-Year = FORMAT('table'[Date],"YYYY-MM")
Now it's getting displayed as (YEAR and Month number) but I want to change it as month name.
After changes in data view, when I close apply, the column is present but there is no data type visible.
Should I create different calculated fields for year and month separately and then concatenate it?
any help would be appreciated.
If you want month first, then maybe you should specify it that way.
Mon-Year = FORMAT('table'[Date],"MMM-YYYY")
This may be useful for you:
https://learn.microsoft.com/en-us/dax/custom-date-and-time-formats-for-the-format-function

Conditional LabelsFormat on Report Builder Chart

I am trying to design a SSRS report where the end user can choose whether they want to view certain charts grouped by year or by month. The user chooses a value for the parameter #dategroup to determine this.
If #dategroup is "YEAR" the SQL groups and pulls row counts for the last 6 years. If #dategroup is "MONTH" it groups and pulls the last 6 months. The SQL is working fine, but I am struggling with getting the horizontal axis labels to format correctly on my report builder charts.
My query passes a "cte_date" column to the horizontal axis which is a date field. When the report is grouping by month I use the LabelsFormat properties grab the month part of the date. For example, if the query passes the value 2019-01-01 to the chart the LabelsFormat will convert that to "Jan". In this case the property LabelsFormat value is "MMM". When #dateformat is "YEAR", the horizontal axis in this case would be "2019", LabelsFormat "yyyy".
I have tried customizing the LabelsFormat property to
Iif(Parameters!dategroup.Value=YEAR,yyyy,MMM)
But this is not returning the desired results (month part if grouped by month, year part if grouped by year). Is there a way to format axis labels (which are dates) based on a parameter value?
The code in the question was close, it just needed some formatting changes. Add double quotes to the parameter value and formats. Enter the below code into the LabelsFormat property of the axis you want changed.
=IIf(Parameters!dategroup.Value="YEAR","yyyy","MMM")
If the #dategroup parameter is set to "YEAR", it will format the date to show just year. Otherwise, it will format date to the three letter month code.

how to get number of days from relative dates filter?

I want to get number of months user selected using Relative Dates Filter?
If user entered "Last 3 Months" then I wants to get number of days for 3 months to use these days in another calculated field.
Calculated field which is using this is as follows.
([Total Sale within Entered Date]/[Number of Days])*365
which returns me predicted sales for the whole year.
Here, [Number of Days] is the filter which I am using. Picture added for Relative Dates filter I am using.
Screenshot of Relative Date Filter:
You need to create a calculated field that works out the number of days in the data.
Something like datediff('day',min([dates]),max([dates])) if data is present for all the days in the time period will work. This calculation will dynamically give you the number of days between the first and last date in the [dates] field for whatever data is selected by the filter (so won't be precise if not all the possible dates are represented in the dataset).

Error using [Today] in Sharepoint filter

I'm having issues creating a filtered view in a SharePoint list. The filter should display any results with a Created date from "this week". In my case, "this week" is from the previous Saturday through the upcoming Friday.
I get the error message "Filter value is not in a supported date format." when trying to create the filtered view.
Here are my filters:
Show the items when column
Created
Is Greater than or Equal to
[Today]-WEEKDAY([Today])
and when column
Created
Is Less than or Equal to
[Today]-WEEKDAY([Today])+6
What am I missing? And is it as simple as I'm guessing it probably is?
You can't use complex formula in Filters - you have to keep it simple like [Today]-30 for last 30 days.
The solution is to turn the problem on its head and add calculated columns to work out the start of the week and the end of the week then filter when the current date is between those dates (i.e. Start <= [Today] AND End >= [Today])
This post gives you more details - its based on the Current Calendar Month but the same technique can be sued for calendar week - see formula at bottom.
http://blog.pentalogic.net/2009/11/howto-filter-items-current-calendar-month-view-sharepoint/