Previous Year YTD till Same Date - 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

Related

Tableau Function - Dates (Day)

I am looking for a tableau formula that would help me create a field that assigns what day number it is in the year. If I use format options the day number restarts every month in the year... I have also tried to create my own formula however it is counting all the days numerically however it does not restart the count after the year ends. I have provided the Formula below:
DATEDIFF('day',DATE('1900-01-01'), [Date: ReportDate]) + 1
I have tried changing the format of the date and I have tried creating a formula to count days and have failed at both :(
Try using : DATEPART('dayofyear', [date])
Assuming you are in a year filtered on 2022, try applying AVG()

How do we calculate difference and percent difference between two columns in tableau

]Difference and percent Difference must be calculated.
I cannot do Apr20-MAy20 because it is not always the same. I need to show the current month and previous month
So I did a relative filter to just show the current month and previous month.
So the difference of two columns should automatically change when the month changes.
Now how do I get the same month of prior year, how do I filter ?
I also need to calculate the difference of current year same month and previous year same month.
Thank you in advance for any help!
When I do table across difference, the difference value is overwriting the existing May and Apr month values as the below screen shot, how to show the difference in another column
Currently:
Below is Expected:
Sounds like you should create a custom filter for the dates. You want:
This month this year
This month last year
Last month this year
There are a number of ways you could do this. I'll give one example and will assume there aren't any future dates in your data set.
[DateFilter]: DATETRUNC('month',[YourDateField])>=DATETRUNC('month',DATEADD('month',-1,TODAY())) OR DATETRUNC('month',[YourDateField])=DATETRUNC('month',DATEADD('year',-1,TODAY()))
Put the to the filters shelf, set to True, and it should keep the months you want.
Then you can just use the standard table calculations to calculate Difference and Percent Difference.
Note, the formula isn't tested, just typed directly into here, let me know if it doesn't work
Based on your comments look at creating separate calculations for to YoY / MoM / etc calculation. That also means creating calculated fields to isolate the Current Month, Previous Month, etc.
For example, the current month:
[isCM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',TODAY())
The previous month:
[isPM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',DATEADD('month',-1,TODAY()))
Then month on month, something like:
[MoM]: (SUM([Measure])*INT([isCM]))/(SUM([Measure])*INT([isPM]))
To make your table check this article about using the placeholder technique to create tables in Tableau

Power BI Week Visual Filtering

Power BI novice here. I have multiple reports which require date filtering by week. I can sometimes get the data to display with my Week column using dates from a column in the same table.
I thought building a Week column based on the date column would result in an easy to use visual. The week column is calculated by:
WeekYear = IF(
FORMAT(WEEKNUM(START.[Date],1)-1,"00"="00",
"Wk53-" & YEAR(START.[Date])-1,
"Wk" & FORMAT(WEEKNUM(START.[Date],1)-1,"00") & "-" & YEAR(START.[Date]))
This results in an x-axis displaying weeks in this format: Wk52-2019. If the underlying data of column STARTis in the proper datetime format, what could be the issue?
I noticed data on the visual which is not filtered for a date range display without issue. Trying to filter with DATESINPERIOD or other DAX date filters caused calculated measures to not display or break the model. I know a lot of references state having a separate calendar table is critical and I suppose I don't fully understand. Thanks in advance.
If you are trying to create the week in date format, then you can use the following calculation:
Week = Table[Start] - WEEKDAY(Table[Start],2)+1
This returns the Monday date of the week, if you want other days you can adjust the calculation accordingly.
If this is not what you are looking for, then you might have to clarify your requirements a bit more.

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.

How to find last month of rolling year in tableau?

I have a requirement in which I have to show the data of last month of each year. So I used a max_month LOD expression which is working fine for all the years except rolling year. My rolling year ranges from Aug 2017 to July 2018. Now when I am using max_month filter for rolling year it is showing me the data of december 2017, but in actual I want to show july 2018. What will be the right approach to fix this?
I am not sure even if your formula worked, its missing basic syntax, and based on your explanation table calculation is missing the Computation logic.
Implemented the same at my end and below is the logic.
Formula to be used:
If MAX(MONTH([Order Date]))=WINDOW_MAX(MAX(MONTH([Order Date])))
THEN 'TRUE'
ELSE 'FALSE'
END
For this table calculation you need to compute along year and corresponding dimension and reset at every year (I guess you are missing this in your current logic).
Let me know how it goes