March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
133 | |
90 | |
88 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
70 | |
68 |