Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have some simple data I am trying to compare between this year and the prior year. THe data is in two columns: Date and Premium. I have created measure called:
Premium TY = sum(Sheet1[Premium])
and then have created a second measure to output last year's data which is:
Premium LY = calculate([Premium TY],SAMEPERIODLASTYEAR(all(Sheet1[Date].[Date])))
Unfortunately the output for the first measure is the same as the output for the second measure: it appears that the Premium LY is not being filtered by the SAMEPERIODLASTYEAR function. All the data is in one table. Any ideas?
Thanks
Solved! Go to Solution.
Hi sirgseymour,
Sameperiodlastyear() will return a table that contains a column of dates shifted one year back in time from the dates in the specified dates column, in the current context. So the fucntion is based on current context which should not be used in your senario.
As a workaround, create a measure using DAX like this pattern and check if it can meet your requirement:
Result = VAR Previous_Year = DATE(YEAR(MAX(Table1[Date])) - 1, MONTH(MAX(Table1[Date])), DAY(MAX(Table1[Date]))) RETURN CALCULATE(MAX(Table1[Sales]), FILTER(ALL(Table1), Table1[Date] = Previous_Year))
Regards,
Jimmy Tao
Hi @sirgseymour
I dont see any filer for This year Premium? Do you want to consider something like below for Premium TY?
Premium TY= CALCULATE(SUM(Sheet1[Premium]),FILTER(Sheet1,YEAR(Sheet1[Date])= YEAR(TODAY())
Try this formula for last year premium:
Premium LY = calculate([Premium TY],SAMEPERIODLASTYEAR(Sheet1[Date]))
If you have dedicated Date dimension table, try this:
Premium LY= CALCULATE(SUM(Sheet1[Premium]),DATEADD(Dates[Date],-1,YEAR)
Thanks
Raj
Hi Raj,
THe data is over a series of years (2014 -2018). What I am looking to compare the prior year data against the current year data for all years. The filtered Premium TY formula that you gave me below only produces the most current year data and I cannot get the Preimum LY to produce any data at all. So, for example if I look at 1/1/2015 for the Premium TY I should see the 2015 data and for the same period the prior year data should be from 2014. All I seem to be able to reproduce using the Premium LY formula is still the current year data.
Thanks
Hi sirgseymour,
Sameperiodlastyear() will return a table that contains a column of dates shifted one year back in time from the dates in the specified dates column, in the current context. So the fucntion is based on current context which should not be used in your senario.
As a workaround, create a measure using DAX like this pattern and check if it can meet your requirement:
Result = VAR Previous_Year = DATE(YEAR(MAX(Table1[Date])) - 1, MONTH(MAX(Table1[Date])), DAY(MAX(Table1[Date]))) RETURN CALCULATE(MAX(Table1[Sales]), FILTER(ALL(Table1), Table1[Date] = Previous_Year))
Regards,
Jimmy Tao
This solution seems to be showing a different number than the previous year's value..
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
99 | |
80 | |
70 | |
59 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |