Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Help will be very much appreciated!
Say if I want to create a measure called "Prior_Sales", now I have two tables I can use - [dim_date] and [sales].
The result should be: given a particular ISO_Year_Week ("202219", meaning ISO Year 2022, week 19), I want to show the sales aggregated for ISO year 2011, week 19.
Here is my SQL code:
SELECT
iso_week,
c.iso_year_week,
Sum(sold_quantity) AS Prior_Sales
FROM [sales] a
JOIN
(SELECT calendar_date, iso_year_week FROM [dim_date] WHERE current_fin_year = 'Previous') b
ON a.calendar_date = b.calendar_date
RIGHT JOIN
(SELECT DISTINCT iso_week, iso_year_week FROM [dim_date] WHERE current_fin_year = 'current') c
-- using right join because ISO week are sometimes 52, sometimes 53
ON a.iso_week = c.iso_week
GROUP BY iso_week,
c.iso_year_week
ORDER BY 2
Solved! Go to Solution.
Hi,
In the case of comparing weeks you could use variables.
If your data format is like you described somethin like this should do:
e.g. [measure] =
End result:
Proud to be a Super User!
Hi,
In the case of comparing weeks you could use variables.
If your data format is like you described somethin like this should do:
e.g. [measure] =
End result:
Proud to be a Super User!
Hi,
For calculating previous years values you can use SAMEPERIODLASTYEAR
[Sales LY]=
CALCULATE([Sales],SAMEPERIODLASTYEAR('Calendar'[Date]))
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
Proud to be a Super User!
Hi Valterri, I just tried this formula and encountered a strange error prompt "an invalid numeric representation of a date value was encountered", do you happen to know what does it mean?
Hi,
I would check whether or not you have NULL values and also what is the data format of your columns. These might be the reason for this error.
Proud to be a Super User!
Hi, thank you again. I guess u r right there might be something with the original data. I don't see any null value or data type issue but when I reimported the original date data it was solved. Thank you very much again!
Hi,
Thanks for your response and this is a great formula to know!
The issue here is that the requirement is to look at the same "ISO Weeks", which are usually not the same dates and it's what complicates the problem.
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |