Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
RGL
Helper II
Helper II

Why don't I get the previous week sales with this measure?

 

Last Week Sales = 

CALCULATE( Sales ,FILTER(VALUES(Calendar[Date]), MAX(Calendar[Date])-7))
 
I get the same result (sales of the current day)
Example: 
 
Date               Sales    Last Week Sales
08/20/2022    175             175
08/21/2022     80               80
 
 
I need to get the sales from 08/13/2022 and 08/14/2022 in the "Last Week Sales" column
 
If I use ALL instead of VALUES I get the total sales of the current week, not from last week
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

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:

vyangliumsft_0-1662024030511.png

(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:

vyangliumsft_1-1662024030515.png

(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 wont return null now: (We need to use the field in our date table Calendar Table)

vyangliumsft_2-1662024030522.png

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.

View solution in original post

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

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:

vyangliumsft_0-1662024030511.png

(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:

vyangliumsft_1-1662024030515.png

(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 wont return null now: (We need to use the field in our date table Calendar Table)

vyangliumsft_2-1662024030522.png

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.

amitchandak
Super User
Super User

@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...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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?

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.