Trying to write a Calculation in Tableau that allows me to Fix Level of Detail on Category where year equal a designated date.
Imagine looks something like
{FIXED [REPORT CATEGORY] : AVG(DOLLARS PAID)} WHERE YEAR = 2015
You have a couple of options.
1) You add the YEAR dimension to the LOD calculation and then add the Year to the filter card and set to '2015'. Your calculation would look like this:
Since you have no YEAR, you need to create a calculated field for it then reference it.
"YEAR" : YEAR(APCD PAID ACCNTS DATE)
{ FIXED [REPORT CATEGORY], [YEAR]: AVG(DOLLARS PAID) }
2) You can restrict the aggregation to only a specific year in the calculation, like so:
{ FIXED [REPORT CATEGORY]: AVG(IF YEAR([APCD PAID ACCNTS DATE]) = 2015 THEN DOLLARS PAID END) }
-- EDIT --
Updated above because you stated you are using a DATE not a number of the year.
Related
I have 4 dates in a month (4 weeks)
like:
var1
2001-01-10
2001-01-15
2001-01-20
2001-01-30
2001-02-10
2001-02-15
2001-02-20
2001-02-30
I want to creat a new var with just the max date in this month:
like:
var2=max(var1) for the same month
0
0
0
2001-01-30
0
0
0
2001-02-30
how can i do this?
I think I understand what you're after, do you only want to show the max DAY for a given month, for every month?
If so, create a table calculation with a formula like this:
{FIXED DATETRUNC('month',[date field]): MAX([date field])}
To explain:
FIXED = apply the aggregate function to only these 'windows' for the calculation. Here we're fixing at the month level. But you could do several layers like month, category, subcategory
: = after the colon you can apply the calculation that you want to do, in your case it's the maximum month
So bringing that together in a sentence, what we're doing is "For each date, truncate to the month level, then for each month, what's the maximum date?"
Hope that helped
How do I dynamically calculate the Year To Date (YTD) for the current year without using a table calculation in Tableau?
I have used the below formulas to calculate YoY for the current year:
if datediff('year',[Date],TODAY())=0 then [Sales] END
For the previous year:
if datediff('year',[Date],TODAY())=1 then [Sales] END
YoY:
sum(current year)/sum(previous year)-1
create a calculated field:
[date] >= MAKEDATE(Year(today()),1,1) and
[date]<= today()
Drag this to filter and select True
It depends on what you're trying to achieve. If you want to filter dates to show only values in the current year without a table calculation, then you could create a calculated field like below and filter on the result:
if Year([Date]) = YEAR(TODAY()) then "YTD" else "Not" END
I want to create a measure which return the maximum date about Orders but before the actual day
I will write an example :
My tables here
(In my table Calendar i have the year 2016,2017,2019, and in my Order table, i have an order for 2016 and 2019,
I want the last date order but before the actual day (18/05/2017), so i want the Date 01/01/2016).
I have 2 table, a dimension Calendar and a fact table Order.
I was thinking about the function filter, so i search how to use filter in
google, and all the solutions i found use 'With' and 'Select'.
(I can't use 'With' and 'Select' when i create a measure in SSAS multidimensional).
Hope i will see your advice.
Just like this similar case in adv cube?
[max order date] return the maximum date about [Internet Sales Amount]
with member [max order date] AS
tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales Amount])).item(0).item(0).PROPERTIES( "name" )
select {[max order date] } on 0 from [Adventure Works]
if yes, then you can create a measure in your cube like this:
Create Member CurrentCube.[Measures].[max order date]
As tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales
Amount])).item(0).item(0).PROPERTIES( "name" );
if only till current day, then(following is refer to adv cube, you need do some code changes per your cube):
Create Member CurrentCube.[max order date] AS
Tail
(
NonEmpty
(
{
Head([Date].[Date].[Date]).Item(0).Item(0)--the first day in your Date dim
:
StrToMember("[Date].[Date].&[" + Format(Now(),"yyyyMMdd") + "]")-- as of current day
}
,[Measures].[Internet Sales Amount]
)
).Item(0).Item(0).Properties("name")
IDE to Write, Analyze, Tuning, Debug MDX efficiently (www.mdx-helper.com)
I have a dataset of dates. It has just one column CreatedOnDate and its values are in datetime as shown below.
This dataset has 6 months of values as shown. I have a parameter called Report Type which has possible values Monthly, Weekly, Daily (Screenshot below)
I have created a calculated field (called Created On Date) which converts the date based on Report Type selected. The formula is shown below
CASE [Report Type]
WHEN "Monthly" THEN DATENAME('month', [CreatedOnDate])
WHEN "Weekly" THEN "Week " + STR(DATEPART('week',[CreatedOnDate]))
WHEN "Daily" THEN STR(MONTH([CreatedOnDate])) + "/" + STR(DAY([CreatedOnDate])) + "/" + STR(YEAR([CreatedOnDate]))
END
This works perfectly. The result of the calculated field is shown below.
I now need to incorporate the following logic
IFF Report Type = "Daily" Display only the last 30 days in the dataset
Other cases Show all values
How do I achieve this?
woodhead92, I'd suggest using so called Level of Detail expressions that were introduced in Tableau v8. First create a calculated field that will calculate the most recent (=MAX) date available:
{FIXED : MAX(CreatedOnDate) }
Let's call this MaxDate LOD. Then adding a new calculated field Show/Hide:
IF [Report Type] = "Daily" AND
([CreatedOnDate] >= DATEADD('day', -30, [MaxDate LOD]) THEN 'Show'
ELSEIF [Report Type] = "Weekly" OR [Report Type] = "Monthly" THEN 'Show'
ELSE 'Hide'
END
Add this filter and select 'Show' value only. I am assuming that you want to see all dates when Weekly/Monthly date granularity is selected - if that's not the case, simply add more ELSEIF conditions.
The formula above could be simplified, but I wanted to make it as verbose as possible so that it helps you understand how Level of Detail expressions work.
One thing to keep in mind - FIXED LOD calculation overwrites filters, so if you have a date-range filter available, you will have to make sure it's added to context. More details on filter context are available here in this a bit out-dated, but still excellent blog post.
Create a calculated field for your condition and then place it on the filter shelf to include only rows that evaluate to true.
[Report Date] <> "Daily" or
datediff('day', [CreatedOnDate], { max[CreatedOnDate] } < 30
The Curley braces are significant, an LOD calculation
I found an example of how to use the Parallel Period function in my SSAS OLAP Cube here: https://www.mssqltips.com/sqlservertip/2915/sql-server-analysis-services-period-over-period-variance-analysis/
However it assumes that you have a Date Hierarchy, which I don't. I tried using it without success. My Date Dimension only has a date attribute and a Year Month attribute (ex: 2015/01 for January 2015). It has no hierarchy nor anything else.
(Interested why? Because it just works, and a hierarchy confused my users)
I need to compare values month over month and year over year.
This is what I could infer with the example, but it is not working:
IIF([Fact Date].[Date].CurrentMember.level.ordinal = 0,
[Measures].[Billed Amount],
(ParallelPeriod([Fact Date].[Year Month].[Year Month],
1,
[Fact Date].[Date].CurrentMember),
[Measures].[Billed Amount]
)
)
What would be the correct syntax to achieve this?
At the end I fixed it adding a Year attribute (ex: 2015), Month attribute (ex: 201501), and made a simple hierarchy (Year, Month, Date). It worked with the following code:
IIF([Fact Date].[Date Hierarchy].CurrentMember.level.ordinal = 0,
[Measures].[Billed Amount],
(ParallelPeriod([Fact Date].[Date Hierarchy].[Month],
1,
[Fact Date].[Date Hierarchy].CurrentMember),
[Measures].[Billed Amount]
)
)