In Tableau, How do I find the difference between [Sales] from the latest date to [Sales]a week ago? - tableau-api

In Tableau, How do I create a calculated field that computes the difference between
[Sales](the latest date) and
[Sales](a week ago)?
nothing yet
nothing yet
nothing yet
nothing yet
nothing yet

Related

Difference between today and 7 days ago

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.

How can I make a database structure in mongodb for saving the date range?

Here I'm saving the date range using golang. Suppose we have to save the all monday comes between the range of the 1-may-2018 to 14-july-2018.
How we will find all the monday between these range using golang and on the other hand we have set the start_time (8:00 A.M.) and the end_time (6:00 P.M.) of the first two coming monday in the database but on the third monday we have a change in the schedule that there is a time change like start_time (9:00 A.M.) and end_time (5:00 P.M.). Then how I will make my database to make this situation in practically using the golang.
Can Anybody help me for this to solve this solution. I made a database for and I do ppr work on it and make some fields shown below:-
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Start_hours (int)
Start_minutes (int)
End_hours (int)
End_minutes (int)
Start_date (timestamp)
End_date (timestamp)
How I will select monday between the selected range and how will I do the situation I explained above can anybody give guidance to me to make this situation easier. Thank you if this is a basic question then I'm really sorry.
I'd make something like this.
Find the first Monday date from the date range (see for example How do I get the first Monday of a given month in Go?
Mondays happen every week, so you can easily find the rest of dates by adding 7 days till the end date
Store all the Monday dates you found with the start and end times
I wouldn't bother with hours and minutes as you can easily get them from the timestamps in Go. Here is the simplified DB structure I would make
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Date (timestamp) // the actual date
Start (timestamp)
End (timestamp)
You don't need any more fields. You can get the day of the week (Day (string) in your structure, e.g. Monday) from the Date field too, but I believe if you want to query the collection by different days, this might speed things up, but be careful if you need to adjust for time zones. If you work with more than one, then store everything in UTC and you may have an extra filed Timezone, cos a date could be Monday for one zone and Sunday for another.
So, the Schedule will hold weekdays and start and end times for each of them. I'm not sure if you need to store initial date ranges, the Schedule collection will hold that range as well, form the first record to the last one. In my mind, I'd initially populate the collection with a given date range, then later on, I can modify it by adding new days, or deleting them.
When you query this collection with some start and end date range for the Date field, if your first result comes newer than 7 days from the start, this means you miss 1 or more entries from the start. If the last result comes older than 7 days from the range end, this means you miss some entries prior to the range end.
There is nothing specific to Go, in my opinion, Go works well with dates and you don't need any special date structures in your DB.

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

Calendar quarter-end immediately preceeding any given date

Essentially I may have any date and I want to get the proper quarter-end date for the previous quarter.
Three examples:
19/07/2013 -> 30/06/2013
30/06/2013 -> 31/03/2013
28/02/2013 -> 31/12/2012
In Excel VBA it seems using DateAdd to subtract a quarter just subtracts three months from the date, e.g. 19/07/2013 -> 19/04/2013. This is no good for me.
What do you think would be the best way of doing this?
Perhaps extracting the month part and then comparing it to a list of the
possible quarters?
Or maybe having some sort of null date
01/01/2000 and then adding the number of quarters the given date
shows as to this null date and then subtracting a day to get a
previous quarter-end position (although this might cause problems
when the date flips under a year to December 31)?
Please consider:
=IF(MOD(MONTH(A1),3)=0,EOMONTH(A1,-3),
IF(MOD(MONTH(A1),3)=1,EOMONTH(A1,-1),
EOMONTH(A1,-2)))
Edit: There is a better answer in the comments.

Number of days between past date and current date in Google spreadsheet

I want to calculate the number of days passed between past date and a current date. My past date is in the format dd/mm/yyyy format. I have used below mentioned formulas but giving the proper output.
=DAYS360(A2,TODAY())
=MINUS(D2,TODAY())
In the above formula A2 = 4/12/2012 (dd/mm/yyyy) and I am not sure whether TODAY returns in dd/mm/yyyy format or not. I have tried using 123 button on the tool bar, but no luck.
The following seemed to work well for me:
=DATEDIF(B2, Today(), "D")
DAYS360 does not calculate what you want, i.e. the number of days passed between the two dates – see the end of this post for details.
MINUS() should work fine, just not how you tried but the other way round:
=MINUS(TODAY(),D2)
You may also use simple subtraction (-):
=TODAY()-D2
I made an updated copy of #DrCord’s sample spreadsheet to illustrate this.
Are you SURE you want DAYS360? That is a specialized function used in the
financial sector to simplify calculations for bonds. It assumes a 360 day
year, with 12 months of 30 days each. If you really want actual days, you'll
lose 6 days each year.
[source]
Since this is the top Google answer for this, and it was way easier than I expected, here is the simple answer. Just subtract date1 from date2.
If this is your spreadsheet dates
A B
1 10/11/2017 12/1/2017
=(B1)-(A1)
results in 51, which is the number of days between a past date and a current date in Google spreadsheet
As long as it is a date format Google Sheets recognizes, you can directly subtract them and it will be correct.
To do it for a current date, just use the =TODAY() function.
=TODAY()-A1
While today works great, you can't use a date directly in the formula, you should referencing a cell that contains a date.
=(12/1/2017)-(10/1/2017) results in 0.0009915716411, not 61.
I used your idea, and found the difference and then just divided by 365 days. Worked a treat.
=MINUS(F2,TODAY())/365
Then I shifted my cell properties to not display decimals.
If you are using the two formulas at the same time, it will not work...
Here is a simple spreadsheet with it working:
https://docs.google.com/spreadsheet/ccc?key=0AiOy0YDBXjt4dDJSQWg1Qlp6TEw5SzNqZENGOWgwbGc
If you are still getting problems I would need to know what type of erroneous result you are getting.
Today() returns a numeric integer value: Returns the current computer system date. The value is updated when your document recalculates. TODAY is a function without arguments.
The following worked for me. Kindly note that TODAY() must NOT be the first argument in the function otherwise it will not work.
=DATEDIF( W2, TODAY(), "d")
Today() does return value in DATE format.
Select your "Days left field" and paste this formula in the field
=DAYS360(today(),C2)
Go to Format > Number > More formats >Custom number format and select the number with no decimal numbers.
I tested, it works, at least in new version of Sheets, March 2015.