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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
vsmn
Regular Visitor

Having problems with previous weeks data

I can't seem to get this working, has the result is somewhat incorrect.

I would like to display the previous week SUM or AVERAGE. There can be cases of non existent data in the previous week, for example:

Week 40 = 100

Week 39 = 101

Week 37 = 90

 

In my table I have a column for the week number, and this is the measure I have:

 

Average Previous Week = 
VAR CurrentWeek = MAX(Carregar[Week of Year])
VAR CurrentTotal = AVERAGE(Carregar[Price])
VAR previous_price = 
    CALCULATE(
        AVERAGE(Carregar[Price]),
        FILTER(
            ALL(Carregar[Week of Year]),
            Carregar[Week of Year] = CurrentWeek - 1
    )
    )
RETURN
IF(
    ISBLANK(previous_price),
    CurrentTotal,previous_price
)

 

Somehow the result is innacurate:
vsmn_0-1730648389101.png

What am I doing wrong?

2 ACCEPTED SOLUTIONS
rajendraongole1
Super User
Super User

Hi @vsmn - I see the problem with your measure. The issue is likely occurring because ALL(Carregar[Week of Year]) removes all filters on the week context, causing unexpected results.

 

updated measure: can you please check with below

Average Previous Week =
VAR CurrentWeek = MAX(Carregar[Week of Year])
VAR PreviousWeek =
MAXX(
FILTER(
ALL(Carregar),
Carregar[Week of Year] < CurrentWeek && NOT(ISBLANK(Carregar[Price]))
),
Carregar[Week of Year]
)
VAR PreviousWeekPrice =
CALCULATE(
AVERAGE(Carregar[Price]),
Carregar[Week of Year] = PreviousWeek
)
RETURN
IF(
ISBLANK(PreviousWeekPrice),
BLANK(), // or use CurrentTotal if you want to default to current average
PreviousWeekPrice
)

 

Hope this helps,try applying this measure, and let me know if it resolves the issue in your table.

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

vojtechsima
Super User
Super User

Hello, @vsmn ,

here's a simple version:

 

previousWeekTotal = 
var currentWeek = SELECTEDVALUE('Table'[week])
var previousWeek = MAXX(FILTER(ALL('Table'[week]), 'Table'[week] < currentWeek), 'Table'[week])
var result =  
CALCULATE(
    [total],
    'Table'[week] = previousWeek
)

return result

 


I would scratch the "-1" check and just get any first value that is lower than current value (week).

 

vojtechsima_0-1730651497041.png

Alternative and that'S what you want, you can show blank if it's not the right week like this:

previousWeekTotal = 
var currentWeek = SELECTEDVALUE('Table'[week])
var previousWeek = MAXX(FILTER(ALL('Table'[week]), 'Table'[week] < currentWeek), 'Table'[week])
var result =  
CALCULATE(
    [total],
    'Table'[week] = previousWeek
)
var isFollowing = IF(previousWeek = (currentWeek-1), result, BLANK())

return isFollowing

 

vojtechsima_1-1730651664965.png

 






Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.

View solution in original post

2 REPLIES 2
vojtechsima
Super User
Super User

Hello, @vsmn ,

here's a simple version:

 

previousWeekTotal = 
var currentWeek = SELECTEDVALUE('Table'[week])
var previousWeek = MAXX(FILTER(ALL('Table'[week]), 'Table'[week] < currentWeek), 'Table'[week])
var result =  
CALCULATE(
    [total],
    'Table'[week] = previousWeek
)

return result

 


I would scratch the "-1" check and just get any first value that is lower than current value (week).

 

vojtechsima_0-1730651497041.png

Alternative and that'S what you want, you can show blank if it's not the right week like this:

previousWeekTotal = 
var currentWeek = SELECTEDVALUE('Table'[week])
var previousWeek = MAXX(FILTER(ALL('Table'[week]), 'Table'[week] < currentWeek), 'Table'[week])
var result =  
CALCULATE(
    [total],
    'Table'[week] = previousWeek
)
var isFollowing = IF(previousWeek = (currentWeek-1), result, BLANK())

return isFollowing

 

vojtechsima_1-1730651664965.png

 






Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.
rajendraongole1
Super User
Super User

Hi @vsmn - I see the problem with your measure. The issue is likely occurring because ALL(Carregar[Week of Year]) removes all filters on the week context, causing unexpected results.

 

updated measure: can you please check with below

Average Previous Week =
VAR CurrentWeek = MAX(Carregar[Week of Year])
VAR PreviousWeek =
MAXX(
FILTER(
ALL(Carregar),
Carregar[Week of Year] < CurrentWeek && NOT(ISBLANK(Carregar[Price]))
),
Carregar[Week of Year]
)
VAR PreviousWeekPrice =
CALCULATE(
AVERAGE(Carregar[Price]),
Carregar[Week of Year] = PreviousWeek
)
RETURN
IF(
ISBLANK(PreviousWeekPrice),
BLANK(), // or use CurrentTotal if you want to default to current average
PreviousWeekPrice
)

 

Hope this helps,try applying this measure, and let me know if it resolves the issue in your table.

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.