Difference between today and 7 days ago - tableau-api

I spent some hours googling now but I can't find a solution that fits, so you guys are my last hope.
I have sales data that is not aggregated (every single item sold listed seperately). I aggregate them in Tableau by Date so I can see on what day we sold which amount if items. What I'm trying to do now is compare the value of today (Saturday) with the value of last Saturday. My problem is that I dont know how to aggregate the sales of 7 days ago and today in the same table so I can compare them.
Is there a proper way in tableau to do this? Really grateful for every answer.

Create a calculation as below:
IF [Order Date]= TODAY() THEN 'Today'
ELSEIF [Order Date]=DATEADD('day',-7,TODAY()) THEN '7 Days Ago' END
Now build the view and filter out nulls from label field.

Related

How to calculate the last week of every month?

I've been having a look around but I can't seem to find anything that answers this question. I want to calculate the date for the last week of every month. For example, the date for the last week of April 2021 is 26-04-2021. I want a date, not a week number.
I use Google Big Query, I do have a calendar table I could use to extract year and month.
Thanks,
Emily
Try date_trunc:
SELECT date_trunc(last_day(month1st, month), week(monday))
from unnest(GENERATE_DATE_ARRAY('2021-01-01', '2021-12-01', interval 1 month)) AS month1st;

Tableau Fiscal Date Calculation

How can I get this outcome in Tableau?
I am trying to compare This Fiscal Year Vs Last Fiscal Year Revenue Data.
I need a calculation that will be able to add an extra day for order_date dimension.
Please help!
dateadd('day',1,[order date])
Check out this link for more date calculations.
https://help.tableau.com/current/pro/desktop/en-us/functions_functions_date.htm

Sum from/to date

I have 3 tables, one with stocktakes conducted last year, one with stocktakes conducted this year and one with sales. All of them are joined by date to one table where I have dates.
Now the question is what can I do to get table with:
store name/ last year stocktake date/ this year stocktake date/ sum of sales from last year stocktake date to this year stocktake date.
If you choose store, than stocktake date from one table, stocktake from second table all looks good, the problem is that I can't get sales to show from/to.
C2Csales = calculate(sum(PP_SalesLessTax[SalesLessTax]),PP_SalesLessTax[date] >= [ly date])
[ly date] is just a measure with last year stocktake date
I have a feeling that this have to be very easy but have no idea how to get this work
thanks
daniel
please see data model. It is a part of bigger model but I have trimmed it so it is clear what is this about.
data model
And here is what I need. Please see picture.
thanks for all responses
result required
You don't need two tables to simulate years. You can have just one. The idea of last year should be calculated by a measure. If you have a complete date table with a day for each row without missing days then you can build time intelligence.
If I get you, you need something like this two measures:
Sales = sum(PP_SalesLessTax[SalesLessTax]
Sales LY = CALCULATE ( sum(PP_SalesLessTax[SalesLessTax] , SAMEPERIODLASTYEAR ( DatesTable[DateColumn] )
With this two measures you can take both of them on same visualizations to compare them.
The idea of having from and to can be solved on visualizations. The slicer with a date type column can create a range filter data that will apply for this two created measures.

Tableau, Week to Date, Month To Date, Year to Date parameter

I have a data set spanning 2 years and is updated daily, created a dashboard to give a view of incidents by date group. I have created a parameter using date trunc for Day/Week/Month/Quarter/Year. This is in Tableau.
I am trying to get the parameter to show a Week to date, Month to date and so on view. IE if on Weds 15th Dec I selected the weekly view, it would only show data for every week in the data set for Sat-Weds (My weeks go Sat-Fri) or the monthly view every month between 1st-15th
Ideally I am wanting this as a simple parameter for a drop down menu, I can do the week to date stuff as a rolling sum restarting every week in a separate table, but for ease I just need a date group function that will allow to do this.
Any suggestions would be appreciated.
Cheers
Pete
The solution is 5 parts:
Date Part Parameter
Max date [Max Date]
Dynamic date part of the Max date [Dynamic Date Part Max]
Dynamic date part of the historical dates [Dynamic Date Part]
Filter those date parts <= the Max date [Dynamic Date - Lass than Max]
Date Part Parameter
Max Date
This is the calculation you'd use with your dataset to find the max date.
{ MAX([Order Date]) }
In order to create a good example, I'm going to set my Max date to a specific date the falls in the middle of a week, in the middle of a month and middle of the year. I'm going use June 13th, 2018 as my Max Date.
So, if you want to follow along you can use the below date as your max date. You can also use this data set if you'd like.
DATE(#2018-06-13#)
Dynamic date part of the Max date
DATEPART([Select Date Part], [Max Date])
Dynamic date part of the Historical dates
DATEPART([Select Date Part], [Order Date])
Filter on Historical dates parts <= the Max Date
[Dynamic Date Part] <= [Dynamic Date Part Max]
Now that we have all the pieces we need let's check to make sure they are working as we would expect.
Looks like we're seeing all the days of the month that are <= the 13th.
When we change it to Day of the Week we see only the days of the week <= the 4th day of the week which is Wednesday when the week starts on Saturday.
Now let's calculate the running sum of sales along our dynamic date part to better help you with your example.
Drag the measure you want to calculate the running sum onto the label, then create a quick table calculation. We'll next need to edit this table calculation as so.
You'll then see your calculation working as you would expect.
Hope this was helpful. Happy vizzing!

Previous Year YTD till Same Date

I have requirement, Previous Year YTD till the same date as YTD is returing results for example if the Records in my table is present from 1-jan-2016 to 9-May-2016 then this year YTD will Calculate till 9-May-2016 (this is Working fine ) and Previous year YTD also should calculate till 9-May-2015 from 1-Jan-2015 not for whole year or whole month
I had tried all the solutions mentioned here :- DAX Pattern
MSDN
But didnt get any result yet,
After trying so many solutions finally got the solutions which solves my purpose.
In my fact table I added a column named Invoicedate and format is "YYYYMMDD" the similar column in Date table names as Datekey and fomrat is "YYYYMMDD".
Here is the calculation for YTD:
Revenue YTD:=CALCULATE([Revenue],DATESYTD('Date Master'[Date],"03-31"),ALL('Date Master'))
And the Here is the calculation for Previous Year YTD:-
Revenue PY:=CALCULATE([Revenue YTD],FILTER(ALL('Date Master'[Datekey]),FILTER(VALUES('Sales Details'[InvoiceDate]),'Sales Details'[InvoiceDate]-10000=EARLIER('Date Master'[Datekey]))),ALL('Date Master'))
Benefit of this solution is, it handles the leap year issue well. I got the idea of this solution from :- Chris Webb's BI Blog