Both PREVIOUSMONTH and DATEADD are not working.
I am trying to show the Average of “Actual Duration” for Previous Month in a table “VMC based on Project Completion Date”. I need a dynamic measure.
As the date column does not show every day (meaning a row is created if there was activity that day) my understanding was that I need a Calendar Date table to use PREVIOUSMONTH or DATEADD. I have created a table "Dates" with a column "Date" from 1/01/2018 to 31/12/2021.
I have created relationship between two tables.
This is the measure I am trying to create:
AVG in PM =
CALCULATE(
AVERAGE('VMC based on Project Completion Date'[Actual Duration]),
PREVIOUSMONTH(Dates[Date])
)
I get blank result.
I also need to create a measure showing the YTD result in a Previous Month.
This is what I wrote:
Cycle Time =
CALCULATE(
AVERAGE('VMC based on Project Completion Date'[Actual Duration]),
DATEADD(Dates[Date].[Date], -1,MONTH)
)
It does show the Average of 154 which is a current YTD. But as it is April now and I had no transaction for April I could not say if the measure shows YTD for March.
However, when I checked what was YTD result two months ago.
Cycle Time =
CALCULATE(
AVERAGE('VMC based on Project Completion Date'[Actual Duration]),
DATEADD(Dates[Date].[Date], -2,MONTH)
)
The result was still the same 132.
Any help will be appreciated.
AVG in PM =
CALCULATE(
AVERAGE('VMC based on Project Completion Date'[Actual Duration]),
PREVIOUSMONTH(Dates[Date])
)
Cycle Time =
CALCULATE(
AVERAGE('VMC based on Project Completion Date'[Actual Duration]),
DATEADD(Dates[Date].[Date], -1,MONTH)
)
Related
I am trying to create a report that shows total sales for the previous financial year (March-April), the current financial ytd, and the previous month in powerbi. I do not want to include any date attributes in the report or place any date filters on the report.
The 2 measures below are working as expected, but I am running into issues when trying to calculate for the previous month.
This Year = CALCULATE('Fact InvoiceLine'[Total Fare Currency],
DATESYTD(ENDOFYEAR(dateadd('Date'[Date], -2,Year),"3/31"),"3/31"))
Previous Year = CALCULATE('Fact InvoiceLine'[Total Fare Currency],
DATESYTD(ENDOFYEAR(dateadd('Date'[Date], -3,Year),"3/31"),"3/31"))
The closest I have been able to get, though it's still far from what I need.... is this,
Last Month = CALCULATE('Fact InvoiceLine'[Total Fare Currency],
DATESMTD(ENDOFMONTH(dateadd('Date'[Date], -2,YEAR))))
which goes back 11 calendar months, but what I need is to see the total for 1 calendar month. Using PREVIOUSMONTH does not work either, as that requires either a date filter or date value in the report.
Last Month =
CALCULATE([Total Fare Currency],
FILTER(ALL('Date'),'Date'[Date] >= EOMONTH(TODAY(),-2)+1),
FILTER(ALL('Date'),'Date'[Date] <= EOMONTH(TODAY(),-1))
)
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!
Im trying to create a wiondow average calculation of 3 months using "window_avg" function.
So far every month(viewing from the right) I get the correct window average.
However If i filter down using the order date to 1st November to End of Date, then Im not able to get the correct average for December 2015.
What Average Im supposed to Get for Dec 2015 when Order date in filter is 1st Nov to End of Date: (31045 + 75973 + 74920)/3 = 60766
What Average Im getting for Dec 2015 when Order Date in Filter is 1st Nov to End of Date : 75446(Here instead of window average for 3 months it takes wondow average of 2 months)
So the question is :
How can i make sure that even If I filter the values I get the correct window average of 3 months and not based on the filter criteria?
Workbook Link Here
I know that table calculations are based on what is in the view, but still is there a workaround for the same ?
Set your filter to include all the data you want included in your table calc — that is, filter to include any prior months needed in data you want to display. So if December 2017 is the first month you want to display, and if your moving average requires 2 prior months, filter to start in Oct 2017.
Then right click on the headers and ‘hide’ the months you don’t want to display.
Table calcs are computed in Tableau based on the result set returned by the data source in response to Tableau’s query. Filters — other than table calc filters - control what data is included in the query result. Hiding marks just prevents them from being displayed.
The example below does effectively the same thing as described above, but uses parameters and a table calc filter to avoid having to manually hide marks. The calculated field [Within Date Range] is defined as [Order Date] >= DATEADD('month', -2, [Start Date]) and
[Order Date] <= [End Date]
and [Start Date] and [End Date] are parameters.
Be sure to notice the filter based on the index () function. Table calc filters hide values, rather than exclude them from the results.
Here's another variation
I understand that we can use the function 'tomonthly' within the financial toolbox but this returns a default monthly data taking the last business day of every month.
What if i want the first business day of every month instead?
I have tried using 'ED' set to 1 in the following manner:
ftsFuture = fints (matlabDate, lnPrice);
monthlyFuture = tomonthly(ftsFuture,'ED',1);
But this was only partially successful in the sense that if the 1st of the month is a working day, it is alright, but if it is not a working day, it becomes the previous working day, which is in the previous month.
I have also tried using 'BusDays' by setting it to 0, in the following manner:
ftsFuture = fints (matlabDate, lnPrice);
monthlyFuture = tomonthly(ftsFuture,'ED',1, 'BusDays',0);
This successfully forces every entry to be the 1st of each month but clearly cannot be correct as some of these dates are clearly not working days!
Any help with this is vastly appreciated!
There is a way to extract the data from daily financial time series in monthly periods starting on the first business day of the month. We can get dates in the middle of the series using tomonthly and busdate functions.
Assuming the data starts at the beginning of some month and ends at the end certain month, we add the first date and eliminate the last date we will get after the operations.
ftsFuture = fints (matlabDate, lnPrice);
monthlyFuture = tomonthly(ftsFuture);
eomDates = monthlyFuture.dates ; % getting end of month business days)
fomDates = busdate(eomDates) ; % getting first month bussines days)
fomDates(end)=[] ; % deleting the last date in the array (out of range otherwise).
firstday = ftsFuture.dates(1); % adding the first date of the series.
fomDates = [firstday ; fomDates];
fomDates = datestr(fomDates);
fomftsFuture = ftsFuture(fomDates);
BO Version: 12.1.0 on Infoview,
O/S: W7
I am creating a report in infoview, which is a cross-tab. I have departments on the row side and for the column I want to have all Saturday dates dynamically displayed, and this is dependent on the date prompt values I put in to the report when I run it.
So if I put in for the prompts Dec the 08th 2013 to Jan the 04th 2014 I should see 4 Saturday dates (14th/21st/28th/04th) along the column headers.
I started off using a variable and using the function relativedate, which gave me all the dates I wanted:
=RelativeDate(LastDayOfWeek([Query 1].[Episode End Date]);-1)
but because I used -1 to get the Saturday date it was giving me the Saturday before the earliest prompt date, so I was getting these dates instead:
(07th/14th/21st/28th/04th)
Is there a way I can get these dates but ignore the previous day (the 7th) before the start prompt date?
I want to have this dynamic so that if I put a date range in it shows me all the saturday dates within that range along the top of the report regardless of the date range period.
Andrew
The reason you're having trouble is that WebI (being ISO compliant) considers a week to run from Monday to Sunday, but your reporting week ends on Saturday.
So, I would approach it this way:
=RelativeDate(
LastDayOfWeek(
RelativeDate([Query 1].[Episode End Date];1)
)
;-1)
If we evaluate some dates with this logic, we'll see the desired result:
Testing 12/8 (Sunday):
Add one day = 12/9
Get Last Day Of Week = 12/15
Subtract one day = 12/14
Testing 12/12 (Thursday)
Add one day = 12/13
Get Last Day Of Week = 12/15
Subtract one day = 12/14
Testing 12/14 (Saturday)
Add one day = 12/15
Get Last Day Of Week = 12/15
Subtract one day = 12/14
I'm at home and don't have access to WebI right now, so I can't test this myself, but the logic should be sound.