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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

sales of last week

 
Hi, I wrote this function to calculate the sales for the current week. 

Sales Current Year =
CALCULATE([Sales], FILTER(ALL(Time),Time[Week Rank]=max(Time[Week Rank])))

But I want to know the sold for the week before the current week so I wrote
Sales Past Year = CALCULATE([Sales], FILTER(ALL(Time),Time[Week Rank]=max(Time[Week Rank])-1))

but this doesn't work, beacuse it returns me BLANK. Only if i put -100 it return me something.

Plus, i would like to calculate sales of previous week of past year.

What should i write?

thank you
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Thanks for the reply from @rajendraongole1 , please allow me to provide another insight: 

 

You can try this.

Sales Same Week Last Year =
VAR CurWeek = WEEKNUM(TODAY(), 21)
VAR CurYear = YEAR(TODAY())
VAR SameWeekLastYear = CurWeek
VAR LastYear = CurYear - 1
RETURN
SUMX(
    FILTER(
        ALL(Time),
        Time[number week] = SameWeekLastYear && Time[Year] = LastYear
    ),
    [Sold]
)

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

6 REPLIES 6
Anonymous
Not applicable

Hi @Anonymous ,

 

Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster? Thank you very much for your kind cooperation!

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

rajendraongole1
Super User
Super User

Hi @Anonymous -Create a measures to avoid issues with context and gaps in the Week Rank, i am using EARLIER function to correctly refer to the previous week.

 

Sales Previous Week =
CALCULATE(
[Sales],
FILTER(
ALL(Time),
Time[Week Rank] = MAX(Time[Week Rank]) - 1
)
)

 

create a measure for previous Week Last Year:

Sales Previous Week Last Year =
VAR CurrentWeekRank = MAX(Time[Week Rank])
VAR PreviousWeekRankLastYear =
CALCULATE(
MAX(Time[Week Rank]),
FILTER(
ALL(Time),
Time[Year] = MAX(Time[Year]) - 1 &&
Time[Week Rank] < CurrentWeekRank
)
)
RETURN
CALCULATE(
[Sales],
FILTER(
ALL(Time),
Time[Week Rank] = PreviousWeekRankLastYear &&
Time[Year] = MAX(Time[Year]) - 1
)
)

 

check the above measure still returns any blanks. Hope it works

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





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

Proud to be a Super User!





Anonymous
Not applicable

 where did you use EARLIER? i don't see it, thank you!

Hi @Anonymous - The EARLIER function isn't directly used in the above dax funtion but can be helpful in some scenarios for row contect. we can use direct approach with variables to handle context and gaps in the Week Rank effectively.

 

try with above measure and let me know.

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





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

Proud to be a Super User!





Anonymous
Not applicable

i wrote this function and now it works, for sales past week

Sales Past Week=
VAR CurWeek = WEEKNUM(TODAY(), 21)
VAR CurYear = YEAR(TODAY())
VAR PrevWeek = IF(CurrtWeek = 1, CALCULATE(MAX(Time[number week]), ALL(Time), Time[Year] = CurrentYear - 1), CurrentWeek - 1)
VAR Prev_Year = IF(CurWeek = 1, CurYear - 1, CurYear)
RETURN
SUMX(
    FILTER(
        ALL(Time),
        Time[number week] = PrevWeek && Time[Year] = Prev_Year
    ),
    [Sold]
)

but how i edit this to have same week for past year? Thank you
Anonymous
Not applicable

Hi @Anonymous ,

 

Thanks for the reply from @rajendraongole1 , please allow me to provide another insight: 

 

You can try this.

Sales Same Week Last Year =
VAR CurWeek = WEEKNUM(TODAY(), 21)
VAR CurYear = YEAR(TODAY())
VAR SameWeekLastYear = CurWeek
VAR LastYear = CurYear - 1
RETURN
SUMX(
    FILTER(
        ALL(Time),
        Time[number week] = SameWeekLastYear && Time[Year] = LastYear
    ),
    [Sold]
)

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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