Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Last Week Sales =
Solved! Go to Solution.
Hi @RGL ,
According to your description, When you use the DATEADD() function, it returns an error when using the week as a dimension, and returns null .Right?
DATEADD() is a time intelligence dax function. If you want to expand the Time-Dimension, it is recommended to use it in a standard date table to avoid errors.
You can also refer to the document: DATEADD()
Here are the steps you can follow:
(1)This is my test data:
(2)We can create a data table according our table ‘Sheet2’:
Calendar Table = ADDCOLUMNS(
CALENDAR(FIRSTDATE('Sheet2'[LastRefresh]),LASTDATE('Sheet2'[LastRefresh])),
"year", YEAR ( [Date] ),
"quarter", ROUNDUP(MONTH([Date])/3,0),
"month", MONTH([Date]),
"weeknum", weeknum([Date]),
"year & quarter", year([date]) & "Q" & ROUNDUP(MONTH([Date])/3,0),
"year & month", year([Date]) * 100 + MONTH([Date]),
"year & weeknum", year([Date]) * 100 + weeknum([Date]),
"weekday", WEEKDAY([Date])
)
We also need to create a one-to-many relationship between two tables, like this:
(3)We can create a measure : “Last Week Sales”:
Last Week Sales = CALCULATE(SUM('Sheet2'[Sales]),DATEADD('Calendar Table'[Date],-7,DAY))
Then the measure won’t return null now: (We need to use the field in our date table “Calendar Table”)
If this method does not meet your needs, you can provide us your sample data without sensitive data, or detailed input and output sample data, so that we can better help for you.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @RGL ,
According to your description, When you use the DATEADD() function, it returns an error when using the week as a dimension, and returns null .Right?
DATEADD() is a time intelligence dax function. If you want to expand the Time-Dimension, it is recommended to use it in a standard date table to avoid errors.
You can also refer to the document: DATEADD()
Here are the steps you can follow:
(1)This is my test data:
(2)We can create a data table according our table ‘Sheet2’:
Calendar Table = ADDCOLUMNS(
CALENDAR(FIRSTDATE('Sheet2'[LastRefresh]),LASTDATE('Sheet2'[LastRefresh])),
"year", YEAR ( [Date] ),
"quarter", ROUNDUP(MONTH([Date])/3,0),
"month", MONTH([Date]),
"weeknum", weeknum([Date]),
"year & quarter", year([date]) & "Q" & ROUNDUP(MONTH([Date])/3,0),
"year & month", year([Date]) * 100 + MONTH([Date]),
"year & weeknum", year([Date]) * 100 + weeknum([Date]),
"weekday", WEEKDAY([Date])
)
We also need to create a one-to-many relationship between two tables, like this:
(3)We can create a measure : “Last Week Sales”:
Last Week Sales = CALCULATE(SUM('Sheet2'[Sales]),DATEADD('Calendar Table'[Date],-7,DAY))
Then the measure won’t return null now: (We need to use the field in our date table “Calendar Table”)
If this method does not meet your needs, you can provide us your sample data without sensitive data, or detailed input and output sample data, so that we can better help for you.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@RGL , Try like
CALCULATE( Sales ,dateadd(Calendar[Date]), -7, Day ))
Or you can refer the Rank approach
Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8
Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
I tried CALCULATE( Sales ,dateadd(Calendar[Date]), -7, Day ))
and it works in a table by date like the one I showed in my example
BUT when , instead of date, I group by week number, I get blanks,
why don't I get the aggregate of the previous week sales?
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
86 | |
84 | |
83 | |
67 | |
49 |
User | Count |
---|---|
131 | |
111 | |
97 | |
71 | |
67 |