Power Pivot DAX formula to compare this year vs previous performance when no date column available - excel

I have a large dataset with 7M records. I have aggregated monthly data for the past 4 years and Lowest level of granularity is at month level with Month number. I need to construct a power pivot table to calculate % difference between this year's performance (YTD) to previous year (YTD last year) on the fly. The SamePeriodLastYear and ParallelPeriod function does not work as the data is not at individual date level. Any help would be greatly appreciated.

create a date column in your monthy data like for april 2017- 1/4/2017 take 1st date of every month
and create a date dimention table that will have continuos date and connect monthly data to date dimention using date column of monthly data
and in SamePeriodLastYear and ParallelPeriod function use date colun of date dimention

Related

Date table in SSAS Tabular model not working

I built an SSAS Tabular model cube and created a date table using calendarauto(). I have marked it as a date table and created a relationship with the fact table using the date column, and both columns have a Datetime data type.
When I analyze the data using excel, the date filter is not working correctly. For example, when I filter on the year 2021, it gives me row values for the year 2019 also, but if I use the date column from the fact table, I get the correct results.
When I analyze the Tabular cube using Power BI, it works right.
Could you please suggest what exactly is going wrong with our date table?
When I put the Fact table date column and date table date column on excel it looks like the screenshot below.
First, I think that is a bad IDEA to use CALENDARAUTO because it searching for all date columns from your model (and if you have a Customer with a born date eg. 1912-02-02, then you create a big table from that date).
CALENDARAUTO ignores calculated tables and calculated columns
searching for date columns. Only the imported columns are analyzed to
search for date columns.
Internally, CALENDARAUTO calls CALENDAR providing a date range that
include all the days in the range of years referenced by data in the
model, according to the following rules:
The earliest date in the model which is not in a calculated column or
calculated table is taken as the MinDate. The latest date in the model
which is not in a calculated column or calculated table is taken as
the MaxDate. The date range returned is dates between the beginning of
the fiscal year associated with MinDate and the end of the fiscal year
associated with MaxDate.
A better idea is to use CALENDAR where you have more control
CALENDAR (
DATE ( 2005, 1, 1 ),
DATE ( 2015, 12, 31 )
)
To the topic. Are you sure that you make a relationship on THIS column (in your fact table)? Check also Cross Filtering Behavior -> OnDirection/BothDirection; Show your relationship detail.

DAX for rolling seven day average to pivot chart by year

I'm trying to create a single pivot chart that will show separate years of data on the same date axis for a rolling 7-day average.
So, the x-axis will be text, 01-Jan to 31-Dec, and each year will be a separate series:
It has to be a text x-axis, as 01-Jan will be a category containing data for 01-Jan-2018, 01-Jan-2019, 01-Jan-2020...
In theory, the pivot table setup would have the column (series) as the Year, and the x-Axis (labels) as the date label (column Date).
The values are then from the DAX expression that creates the rolling 7-day average.
The source data (tblSource) has a single column of dates (Date2) that rolls over across years and has the column Year to break it down in the pivot.
The daily value is the one that is averaged (itself and the previous six days).
The 7-day average I normally use in DAX doesn't work here.
I need to have the Date column actually in the pivot rather than Date2, as the axis needs to be text to allow for multiple date years on the same x-axis point, but I can't get a DAX formula to work.
The other consideration is that the formula can't just consider a single year, as the rolling seven day average for 01-Jan-2018 includes the previous six days of 2017, for example.
This is the formula I usually use, but I can't manage to tweak it!
AVERAGEX (
DATESINPERIOD ( tblSource[Date2], LASTDATE ( tblSource[Date2] ), -7, DAY ),
[Sum of Daily Value]
)
But this is the output I get, and nothing has been averaged. I think it's because Date2 is being pivoted off Date, but I'm not sure how I get around that?
Can anybody offer me any help?
It's quite a frustrating problem as it would be trivial for me to do it using code, or doing it manually, but I really am trying to get better at DAX!
Thanks in advance!
Phil.
Update: Thanks to Joao for this.
=VAR d = MAX(tblSource[Date2])
RETURN CALCULATE(AVERAGE(tblSource[Daily Value]),
ALL(tblSource[Date]),
DATESINPERIOD(tblSource[Date2], d, -7, day),tblSource[Year]>0)
I had to use MAX rather than SELECTVALUE as Excel seems to lack that functionality.
I also had to unfilter the Year, so that the rolling average could be calculated from the previous year's date where neccessary.
Thanks.
When you run that measure, your table is being filtered by the date text at each point, so when you pass/create the DATESINPERIOD filter, it creates a table with the last 7 dates, but only one of them is actually available (the one relevant to your current data point).
You need to clear the filters on the table so that you have all the dates available, in order for you average to work. You can achieve this by changing the measure slightly:
VAR d = SELECTEDVALUE(tblSource[Date2])
RETURN CALCULATE(AVERAGE(tblSource[Daily Value]),
ALL(tblSource[Date]),
DATESINPERIOD(tblSource[Date2], d, -7, day))

Comparing Pivot Table Data

Every month I produce a schedule of forecasted orders for the next 5 years by date and part number. I have sorted the data into a pivot table to show material as the rows with Year, Quarter, Month as the columns and the quantity of the order as the values. I need to compare the differences between the report every month. EXAMPLE: If our forecast is 40 of one part in June 2020 and the next month when we run the report the forecast is for 80 in June 2020, I need to be able to see that difference.

DAX year over year comparison

In a report that I am making in DAX I would like to have year over year comparison of a measure defined as:
Sales Count := CALCULATE(COUNT(fData[PN]);fData[Proc.Type]="CU")
This measure basically counts the amount of sales that were generated. I have a dataset that spans from the beginning of 2014 up to today (16/01/2018). My calendar table consists of a date column, a year column and a month column and is ranges from 01/01/2014 up to 31/12/2018 (to avoid contiguous date errors when using time intelligence functions).
I have defined a measure called PY Sales count as:
PY Sales Count := CALCULATE([Sales Count];SAMEPERIODLASTYEAR(dCalendar[Dates]))
This measure does the job I want it to do, aside from one issue. When comparing the month of january of this year to the month of January to last year, it appears that we are doing terrible. This is because the SAMEPERIODLASTYEAR function considers the FULL month of January for the year 2017 and compares it to the period from the first of January until the 16th of January (today).
I think I should thus try to build a custom measure to 'filter' the date table such that when the year over year measure considers the running month, it only takes the same period as the one on which sales were recorded to compare against, not the full period...
However, due to my sparse DAX experience, I cannot seem to get this right...
If anyone could help/assist me on this, that would be hugely appreciated!
Thanks in advance
I haven't had a chance to test this, but try something along these lines:
PY Sales Count := CALCULATE([Sales Count];
FILTER(dCalendar;
dCalendar[Dates] <= DATEADD(TODAY(), -1, year);
SAMEPERIODLASTYEAR(dCalendar[Dates])))

Spotfire Bargraph to show Avg Quality by year for previous years and by month for current year

I have a bargraph which shows the quality of my data for each month. As the data is growing over the years, the graph is getting messy. So, i would like to show Avg Quality by year for all those months in Previous years but monthly for the current year.
Can any one help me how to achieve this.
Thanks,
-Dileep
This needs to be separated into two charts, or it just won't be legible. I'd suggest:
Creating an AVG by Year bar chart graph for all your data
Creating a details visualization of the above Yearly Average data which shows the 12 months of that year with SUM() as your aggregation method. Be sure to have YEAR > Month on your category axis
Thus, if you need to compare 1, 2, 3 or all the years by month you can select them all, or just the ones you want.
I was able to do it with the help of some calculated columns. To help explain, let's assume the value column in your data set is called Value and the date column in your data set is called ValueDate. I created some fictional data that extends into April, 2017 to help illustrate the solution.
Insert a calculated column to classify whether or not the date in each row is in the current year or not. I'm going to call the column DateGrouping.
CASE WHEN Year(DateTimeNow())=Year([ValueDate]) THEN "Monthly" WHEN Year(DateTimeNow())>Year([ValueDate]) THEN "Yearly" END AS [DateGrouping]
Insert a calculated column that tells us the last date of the month for ValueDate. E.g., if the date in the row is 4/10/2015, the last day of the month for the day in that row is 4/30/2015. If the date in the row is 7/8/2013, the last day of the month for the date in that row is 7/31/2013. We'll call this column LastDateOfMonth.
DateAdd("day",-1,date(Year([ValueDate]),Month(DateAdd("month",1,[ValueDate])),1))
Insert a calculated column that tells us the last date of the year for ValueDate. Of course, it's just Dec. 31 of ValueDate's year. Call this column LastDateOfYear.
Date(Year([ValueDate]),12,31)
Finally, we utilize the previous three calculated columns to add a calculated column for the date value we want to plot. You are wanting to plot by month for the current year, and by year for prior years.
CASE [DateGrouping] WHEN "Monthly" THEN [LastDayOfMonth] WHEN "Yearly" THEN [LastDateOfYear] END
On my value axis is the Value column, which I'm aggregating as an Average. On my category axis is the calculated DatePlot column -- I set the category axis to Categorical Scale. And I'm coloring by the calculated DateGrouping column to offer a visual cue that the data is aggregated differently over time.
Now, should this be done? There are certainly some pitfalls. You can't make the category axis Continuous Scale or else you'll see all the empty months when we're lumping prior years into Dec. 31. On the other hand, gaps are good visually when there is no data for a given period. So I don't know. But I pictured what you were asking and decided to try it. Buyer beware!

Resources