I've created a YTD calculated member in an SSAS cube using the ytd()function. This function looks like this:
SUM(
YTD(
[Date].[Calendar].[Calendar Year]
,[Date].[Calendar]
)
,[Measures].[cost]
)
Everything is working fine when in my pivotTable I use the calendar hierarchy in rows(excel 2010). But When I try to use my YTD with the Month level only, I have a value which is the total cost of the year. There is no aggregation by Month. I have something like this:
MONTH | YTD;
01 , 240;
02 , 240;
03 , 240;
04 , 240;
05 , 240;
... , 240;
When I drag the quarter above the month in my report, then I have the expected values. The month is the only level that raises that issue and I don't understand? My date dimension is well declared as time dimension and each attribute set correclty.
I got it! Indeed my time hierarchy wasn't correct. In fact in my Time Attribute Relationships, my YEAR, QUARTER, MONTH attributes were related to the only DATE attribute (set as the primary Key). I just removed the relationship between the Date and QUARTER attribute and I recreated a new one between the MONTH and the QUARTER.
Now my YTD measure is aggregated correctly within months! Problem solved:-)
Related
I'm trying to get Weekly MTD and YTD values based of hourly data, but I'm having difficulties achieving this.
This is the data I'm working with:
max(Date) - Last day of the week
ISOWeek - Week in question
Value - The data I'm trying to sum
SELECT MAX(ISOWeek) AS [ISOWeek]
,MAX(Date) AS [Date]
,SUM(Value1) AS [MTD]
FROM Table1
GROUP BY ISOWeek, FORMAT(Date,'yyMM')
ORDER BY ISOWeek DESC
This is what that query returns:
ISOWeek Date MTD
29 2020-07-19 367529
28 2020-07-12 367138
27 2020-06-30 103290
27 2020-07-05 266755
26 2020-06-28 346588
25 2020-06-21 337168
This is what I would like to get:
ISOWeek Date MTD
29 2020-07-19 261515
28 2020-07-12 184104
27 2020-07-05 103414
26 2020-06-28 432114
25 2020-06-21 346588
The data has to be grouped by ISOWeek, if it's a week that dips into two months, I'm only interested in the MTD of the month in which the week ends. We have hundreds of values, so the plan is to create a MTD view and a YTD view. If I can get some help with the MTD one, I can get the other one done.
I'm nearly sure that what I'm after has to do with a WHERE clause and DATEADD but I'm not too sure what it should say.
Thank you for taking the time.
I don't really follow the rules you would like to apply, but per dates apply the formula to get weekstart/monthend or what you need. Place the date instead of the current date in the example.
Then group by the modified date.
You could build a date dimension where you have the required dates in some columns (first day of month, first day of week,etc.). This way you get a table with all the dates and the matching result for each.
It might be easier/faster to join it on the requried column.
declare #monthstart date,
#monthend date,
#weekstart date
;
select #monthstart=datefromparts(year(current_timestamp),month(current_timestamp),1);
select #monthend=EOMONTH(getdate(),0);
select #monthstart,#monthend,EOMONTH(getdate(),1) as next_month, EOMONTH(getdate(),-1) as previous_month;
select cast(DATEADD(d,1-DATEPART(WEEKDAY,current_timestamp),CURRENT_TIMESTAMP) as date) as Sunday,
cast(DATEADD(d,2-case when DATEPART(WEEKDAY,current_timestamp)=1 then 8 else DATEPART(WEEKDAY,current_timestamp) end,CURRENT_TIMESTAMP) as date) as Monday
;
I have dates in data from
02 Aug 2018
03 Aug 2018
04 Aug 2018
.
.
.
.
30 Aug 2018..
Now i want start of the month date through Dax formula which is 01/08/2018. But in data date is 02/08/2018 which i dont want
i tried below formula
Start_Monthdate = STARTOFMONTH(EStart_Date[Date])
through above formula i get 02 Aug 2018 which i dont want
In DAX, what you can do is use the EOMONTH function.
https://dax.guide/eomonth/
Column Name = EOMONTH(table[date], -1) + 1
So the above DAX is finding the end of the previous month, then adding 1 day to it.
For the date 2/4/2020, EOMONTH gets the date 31/3/2020, then adds one day to get 1/4/2020
Time intelligence only works reliably if you use it on a calendar table that has all the dates in the year you're working with. Since your date column is missing the first day of the month, STARTOFMONTH returns the first one that you do have.
Without creating a proper calendar table, you either use EOMONTH as #Jonee mentioned or try this:
DATE ( YEAR ( EStart_Date[Date] ), MONTH ( EStart_Date[Date] ), 1 )
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 have a SSRS report that has typical Start Date / End Date parameters that will filter out Sales Order information based on the OrderDate field. With this report, I have a subreport. This subrebort is basically nothing more than an aggregation of the same info, by month. This aggregate information should be from the first day of the month, one year prior, through the last day of the End Date's parameters month. This does not take the main subreports Start Date parameter into consideration at all.
This is where it gets a little tricky. For example, lets say I made the start date / end date parameters on my main report:
10/15/2016 - 11/15/2016
(just remember, for this purpose, the start date is irrelevant)
I would want the subreport to show the sales totals, per month, for the ENTIRE month of December 2015 through the ENTIRE month of November 2016, even though my end date was 11/15/2016.
If I were to put in those same dates for my parameters in the report right now, for the aggregation of December 2015, I would only get sales from the 15th through the 31st. Currently I have my subreport to filter on the OrderDate by:
Fields!OrderDate.Value>= DateAdd(DateInterval.Month, -12,Parameters!EndDate.Value)
I know that this filter is not currently set up to have an end date for the parameter, just a greater than argument, which is wrong since I want the 12 month history to stop at the last day of the month for the month of my End Date parameter, but I don't know how to make that happen either.
I hope I have explained this well. Any help on this would be greatly appreciated.
You can set a filter to get only dates between a specific range in your subreport dataset, tablix and some visualizations:
In DataSet properties or Tablix Properties in the Filter tab use these settings:
In the Value textboxes you should use the expressions to calculate your date range.
StartDate
=DateSerial(Parameters!EndDate.Value.Year-1,Parameters!EndDate.Value.Month,1).AddMonths(1)
EndDate
=DateSerial(
Parameters!EndDate.Value.Year,Parameters!EndDate.Value.Month,1).AddMonths(1).AddDays(-1)
It should filter your data from 12/01/2015 to 11/30/2016 if your EndDate parameter is set to 11/15/2016
Let me know if this helps.
I need to compare data from this year with the data from last year. So the customer wants to switch between full year and year-to-date comparison. The full year i already have, but with year-to-date they want to see how the are going now compared to the data from today last year e.g.:
full data from Jan 2016 - 24. Aug (today) compared to Jan 2015 - 24. Aug 2015.
How to implement this in DAX? I'm using this in Power BI.
Supposing you have a measure called [Sales], calculated from a fact table, and a Dates table, you can write 2 new measures to compare data from this year and the previous:
Sales YTD = CALCULATE ( [Sales]; DATESYTD ( 'Dates'[Date] ) )
Sales PY YTD = CALCULATE ( [Sales]; DATEADD ( DATESYTD ( 'Dates'[Date] ); -1; YEAR ) )
Putting it in a matrix visualization, it would give you the following:
Please remember to have your 'Dates' relationship to the Sales table correctly configured in order to have your time intelligence calculations done right. You can find more info here.