How do I subtract dates from tableau? - tableau-api

How do I subtract dates from tableau?
For example, I want to subtract 1 year from a date variable.
It's from the query, not the filter.
help me

DATEADD('year',-1,[your_field_here])
that's the best way to do it.

Related

How to calculate average for the calendar year

My input file consists of column Actual Exp and Actual Min.
Now I want to create a measure for calculating the average for the current calendar year having the latest month of data for Actual Exp and Actual Min.
I want to calculate the average from Jan'21 to Mar'21, and later if data gets added for Apr or May I would like to calculate the average from Jan'21 to May'21 or Apr'21.
Similarly, I want to have from Jan '21 to Dec'21 in Dec'21 and an average from Jan'22 to Feb'22 in Feb'22. I also have a date filter I don't want my date filter to affect the average.
I tried using TOTALYTD and MAX(Date), but it's not working.
Thanks.
I've not fully understood your question, but hopefully this helps:
AVERAGEX ( ALL(TABLENAME), TABLENAME[COLUMNNAME])
This should give you an average of COLUMNNAME no matter what filters/slicing you have in place.
If you wanted to futher restrict this, you can try creating a 2nd measure such as
CALCULATE(AVERAGEX ( ALL(TABLENAME), TABLENAME[COLUMNNAME]), datetable[monthcolumn] IN {"Jan", "Feb", "Mar"})

Show Week Dates (Start and End) Instead of Week Number

Is there any way to show the start and end for each week ?
or is there any way to make the week start from 1
Try DATETRUNC(‘week’, [Date]} as a calculated field on the columns shelf. Make sure to treat it as a discrete dimension.
It appears that you are using DATEPART() instead of DATETRUNC()

How to Calculate YTD (Jan to prev month) in a single column in tableau

Original post - https://community.tableau.com/thread/206909
I have a report in which I have sales per month in the column and commodities in the row. The data show actual sales and future estimates for each month.
Need to calculate Year-To-Date (YTD) total for 2016 (from Jan to Previous month) and have it in a single column at the end of the actual values.
I already created a calculated field - YTD
IF
YEAR([DATE]) = YEAR(NOW())
AND
MONTH([DATE])< MONTH(NOW())
THEN
[VALUE/UNIT]
ELSE
0
END
But when I add to the view, it creates a another section for YTD with sum for each month till April.
Can someone please help me in how to achieve this in Tableau?
There are couple of ways to achieve this view in Tableau
1. To create calculated field for each Month and YTD and add measure names in Row & Measure values in Text
2. Make union of 2 queries - one that select all the correct values & second that have YTD calculation in month column. Then use pivot it

Concatenate variable horizontally to make one variable in matlab

Is it possible to concatenate multiple variable horizontally to make a single variable in Matlab?
For Example, I want to join:
year = 2001, month = 06, day = 15
to make one variable '20010615' which I could search in a matrix.
I hope I am clear.
Regards,
If you want a string output, use string formatting and sprintf
sprintf('%04d%02d%02d', year, month, day );
If you want a numeric output, simply multiply
day + 100 * month + 10000 * year
Update:
Thanks to #Joshua's comment: if you are indeed working with date/time information you should also look into datestr that allows more speciallized formatting for date and time information.

highcharts x axis date variable range

I have difficulty to make date range in x-axis for highcharts.
It based on user input that can have various date range, can be a month, 14 days, 2 months, etc.
Is it possible to give minimum and maximum date, and let the highcharts arrange the scaling between min and max date?
And how will be the correct syntax?
appreciate for the help.
You can set min/max values for xAxis, but dynamic version can be achived by using variables defiend by user.
http://api.highcharts.com/highcharts#xAxis.min
http://api.highcharts.com/highcharts#xAxis.max