Use a Level of Detail Expression in Tablaeu on 1 of 2 forms of a date variable - date

In Tableau a Level of Detail Expression allows you to create a calculated variable that is affected by none or only some of the view level filters.
I have a view that has 2 filters based on the same column -- a YEAR(Date) filter and a MONTH(Date) filter.
If my Level of Detail Expression is:
{EXCLUDE [Date mdy]: SUM([count.Attrition])}
that won't work because it would remove both date filters. I only want to remove the MONTH date filter.
However, this
{EXCLUDE [MONTH(Date mdy)]: SUM([count.Attrition])}
is an invalid expression and this:
{EXCLUDE MONTH([Date mdy]): SUM([count.Attrition])}
is allegedly valid but doesn't actually work.

Hack-R, how about using FIXED, I think that should help solve this:
{FIXED [Year] : SUM([count.Attrition]) }
Using FIXED is basically forcing Tableau to calculate aggregate measure at specific level - in this case on Year
[Year] is just a simple calculated field which returns Year value.
YEAR([Date mdy])
Creating a dedicated calculated field is probably not really necessary in Tableau 10, but it's just my personal preference to keep things organized.
You might be wonder why EXCLUDE didn't work - I think the main use-case is different with INCLUDE/EXCLUDE and probably best explained in this (a bit lengthly) article.
Hope this helps.

Related

PowerBI month as number

I just simplify and rephrase my question as previously it was more complicated compared to what I really needed.
So I need a solution for how I can see/show the "Month" from a Date hierarchy as a number in any filter or visualization.
That's my simple date hierarchy with Year/Month/Day. I only use the month as I work with periods in my report.
Now if I use "Month" from the hierarchy it is shown by filters and visualizations with the name of the month.:
I would like to see the months as a number.
Also, it is important to use the "Month" from the hierarchy as many DAX use it for calculations.
Could you please help?
Thanks,
András
Since you are not revealing the data model but some screen shoots only it's kind of guess work trying to help you.
In your Periods table you could add a calculated column from
Month Number = MONTH(Periods[Date])
and use this field in your visual instead.

Tableau KPI prev value depending on variable

am trying to get Previous Sum(of someField) based on a variable value which is an Id.
This is not a table, Im doing a KPI
On Qlik you would do something like:
SUM({<Id={"$(=Max(vVariable),-1))"}>} someField)
But I can not achieve it on Tableau, off course is due to my lack of knowledge, unfortunatelly time is tinking at work and wanted to see if anyone has any input!
Thanks
Assuming you may use a sample input like the Superstore (using sales as metric), this could be what you're looking for:
In red you can see your "variable" which allows you to select a value and in blue you'll find the unique row for the previous value (Order ID sorted).
The first thing you need to to do is creating a parameter based on all the Order ID values:
Then things start to get a bit complicated if you're not familiar with LOD (Level of details) and the order of execution in Tableau, especially for filters.
Assuming that you can get some information on your own (otherwise, feel free to ask), the first thing you nee to to do is to "pre-calculate" the equivalent of a table having a rowe for each Order ID, in which you also have the previous Order ID value.
You can achive this combining Fixed (LOD) and Lookup function, creating this Calculated Field "Lookup Order ID":
LOOKUP( max({ FIXED [Order ID] : MAX([Order ID])}),1)
This is actually just a calculated field that you want to "fix" because you need the filter to act after you have made that previous calculus, and then you shift your data by 1 row backward.
Once you've done that, you just nee to create another calculated field in order to test your parametric value, and it could be something like this "check param":
[Lookup Order ID] = [Order ID param]
Moving this calculated field in the filter section and selecting just "true" values, you'll get that unique rows like in the initial image, showing the previous value (blue) related to the one you select in the parameter drop-down menu (red).

Have Max value of range of dates filter be todays date

I have a "Range of Dates" filter and what I want is for the max (or right most value) to always be the most recent date which should be today's date. What seems to be happening is that if I leave the dashboard open and come back the next day the max value is yesterday's date and I must manually move the slider over to be today's date. How can I accomplish this?
I find a calculated field is the best way to do this as I have run into the same issues using the out of the box max date filter.
Create a calculated field as follows:
[date] = {FIXED: max([date])}
This creates a True False field where only the records that have the max data and carried through.
Now drag this onto the filter pane and select 'TRUE'.
I've generally seen two basic approaches for this problem: Calculated fields and relative dates.
Use a calculated field or parameter or some combination of calculated fields and parameters with filters. This is similar to what smb suggests in their answer to this question. It also seems to be the most popular approach.
If you don't particularly care about being able to set the end-date with the slider, you could try using relative dates, using the approaches detailed in the accepted answer to this Tableau forum question and in this Tableau Knowledge Base article. Jennifer Vonhagel also gives a second answer to the Tableau forum question farther down that uses a parameter plus calculated field approach.
Additionally, this Tableau Knowledge Base article offers another option (Option 1, in the article) if you have Tableau 10.3+: You can use the "Latest Date Preset" (see here for details) check box in the date filter dialog box. I haven't used this, but it looks promising if you're using Tableau Desktop (seems like it wouldn't work for Tableau Web). The article's Options 2-4 are just riffs on calculated fields, in my opinion.
Two more approaches I've heard of – but never personally seen in the wild:
Push the max date down into the view you put Tableau on top of and let the view do the work.
Use a script to modify the Tableau workbook's XML.

Microstrategy - AddDays

I need to be able to use the AddDays function to derive the last week from the date column that I have in the dataset.
So, I have delivery_date of 3/21/2018, then I want to derive AddDays('3/21/2018',-7.0) - only that I want to do do this for every row in the dataset. But, the AddDays function only takes a metric. Can you suggest how I can work around this situation?
Thank you in advance,
Abhilash
As usual it depends on what you want to achieve.
If you need an attribute that returns delivery_date - 7, just create a new attribute and in the definition of the expression you can put a formula like [delivery_date] - 7 or use a pass-through function like ApplySimple to write the formula for your database (more info here).
Note: If you do this, you need to do the form expression with the formula (or the ApplySimple) only for the forms mapped on the fact table, the forms mapped on the lookup table (your Day dimension table) should be without formula, otherwise parent level will returns wrong values. Also if you don't a lookup for this new attribute create an alias or enable -Attribute Role Recognization more here.
If you need to calculate metric values for delivery_date - 7, then in that case you need to use a transformation metric. You will need to create a minus 7 days or same day previous week transformation, then associate it to the Delivery Date attribute and create the needed metrics. The last week transformation is included in the MicroStrategy Tutorial project.

Sorting Data by Latest Date, selecting top 10 and charting (v. 10.0.1)

This is the data table that I have created
I need to sort the data by 'April2017' in descending order and then select the top 10 projects.
When we select top10 basis April2017, the output should be
Instead what I get is
Here is what I've tried out so far,
Created a calculated field
Calculation1 = iif([Year_Month]=MAKEDATE(2017,4,1),[Claim Count],0)
Sorted Projects based on 'Calculation1'
Drag Project to Filter and select Top10 based on sum([Calculation1])
I am unable to understand how the top10 here is being derived.
Where am I going wrong?
The chart that I am trying to get should be similar to
Please help me with this problem.
You can filter to a selected portion of data in a calculation and use as desired. So create a calculated field called, say April_2017_Foobars, defined as:
if datetrunc('month', [Year_Month]) = #04/01/2017# then [Foobars] end
This field return [Foobars] for the April 2017 rows and null for other rows. Nulls are ignored by aggregate functions, so if you aggregate with SUM() or AVG() etc, the effect is to filter to April 2017 for that field alone.
Then you can use April_2017_Foobars for sorting and defining top filters for your Project field. This is a very general technique that is useful in all kinds of situations.
You can generalize it a bit to use a parameter for the special month rather than hard code it - or use an LOD calc to find the last month in your dataset if you always intend to use the latest month.
P.S. You can use the makedate() function instead of a date literal if you prefer and your data source supports that function. Might avoid any confusion about date literal formats being different in various countries.
create Calculation1 field: iif([Year_Month]="April 2017",[Number],0)
sort Project in descending order on Calculation1 Sum
drag Project to filters, and do Top > By Field > Top: 10 by Calculation1 Sum