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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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

 

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

 

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors