Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I have a problem in DAX using the SAMEPERIODLASTYEAR function when presenting the data based on weeknumbers. I am struggling with this for more than 10 hours and still did not found the cause of the problem..:(
I am having a cumulative sales measure (year to date):
YTDSales = CALCULATE(SUM(Sales[SalesAmount]);DATESBETWEEN(Date[Date];DATE(YEAR(MAX(Date[Date]));1;1);MAX(Date[Date])))
The measure for creating the 'Sales Previous Year':
SalesPreviousYear = CALCULATE([YTDSales];SAMEPERIODLASTYEAR(Date[Date]))
My date table is dynamic, based on SalesDates (minSalesDate and maxSalesDates are variables):
CALENDAR(DATE(YEAR(minSalesDate);MONTH(minSalesDate);DAY(minSalesDate));DATE(YEAR(maxSalesDate);MONTH(maxSalesDate);DAY(maxSalesDate)))
Everything works fine when I present the data within a table using the columns Date, YTDSales, SalesPreviousYear. When I replace the date column for weeknumber("ww") and set a report filter on year 2017, it does not show the right value for the previous year. The date table is generated until 01-06-2017 and the incorrect value is for weeknumber 22. I think it show a value that should be presented around week 25/26/27.
Does anyone know the cause of the problem that it does not show the correct data for the previous year when I present the data per weeknumber?
Thank you very much.
Solved! Go to Solution.
The inbuilt time intelligence functions must use the date column. If you want to use anything else (like a week number) you must use custom time intelligence. I explain that here http://exceleratorbi.com.au/dax-time-intelligence-beginners/
Is there any reason why you can't use totalytd() to calculate your YTD number? That is the first thing I would try
Thanks for your reply @MattAllington
It is a good point, I will change it. But it does not solve my problem:(
The inbuilt time intelligence functions must use the date column. If you want to use anything else (like a week number) you must use custom time intelligence. I explain that here http://exceleratorbi.com.au/dax-time-intelligence-beginners/
Great. I think this should be the solution.
After reading your blog I do understand the Time Intelligence better and I have figured out a solution (using dateadd).
Thanks.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
58 | |
55 | |
54 | |
38 | |
29 |
User | Count |
---|---|
78 | |
62 | |
45 | |
40 | |
40 |