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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
truttafisker
Helper I
Helper I

Meassure that gets previous year values

Hi there all


I have this meassure ..

 

PrevPeriodSammensat = 
    CALCULATE(
        ROUND(SUMX(MergedInvoices, MergedInvoices[Beløb Uden moms]),2),
        FILTER(
            ALL('Date'), 
            'Date'[Year Number] = SELECTEDVALUE('Date'[Year Number])-1 &&
            WEEKNUM('Date'[Date]) >= MIN('Date'[Weeknumber]) &&
            WEEKNUM('Date'[Date]) <= MAX('Date'[Weeknumber])
        )
)

 

 

but for some reason it doesn't include the 31/12 (int his case 2021) .. 

are there anyone who has an idea why this is ?

1 ACCEPTED SOLUTION
Kaviraj11
Super User
Super User

Hi,

 

The Weeknum function can sometimes cause unexpected results around year boundaries.

 

Try this:

PrevPeriodSammensat =
CALCULATE(
ROUND(SUMX(MergedInvoices, MergedInvoices[Beløb Uden moms]), 2),
FILTER(
ALL('Date'),
'Date'[Year Number] = SELECTEDVALUE('Date'[Year Number]) - 1 &&
(
('Date'[Weeknumber] >= MIN('Date'[Weeknumber]) && 'Date'[Weeknumber] <= 52) ||
('Date'[Weeknumber] <= MAX('Date'[Weeknumber]) && 'Date'[Weeknumber] >= 1)
)
)
)




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

Proud to be a Super User!





View solution in original post

3 REPLIES 3
Kaviraj11
Super User
Super User

Hi,

 

In your measure, you want to include dates that fall within the same week range but in the previous year. Using 'AND' would require both conditions to be true simultaneously, which isn’t possible for week numbers that span across the end of the year. By using 'OR', you ensure that either condition can be true, allowing you to capture the correct range of dates.

 

The reason for not using week 53 is that not every year has a 53rd week. The ISO week date system, which is commonly used, only includes a 53rd week if the year starts on a Thursday or is a leap year starting on a Wednesday. Including week 53 could lead to inconsistencies or errors in years that only have 52 weeks.




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

Proud to be a Super User!





Kaviraj11
Super User
Super User

Hi,

 

The Weeknum function can sometimes cause unexpected results around year boundaries.

 

Try this:

PrevPeriodSammensat =
CALCULATE(
ROUND(SUMX(MergedInvoices, MergedInvoices[Beløb Uden moms]), 2),
FILTER(
ALL('Date'),
'Date'[Year Number] = SELECTEDVALUE('Date'[Year Number]) - 1 &&
(
('Date'[Weeknumber] >= MIN('Date'[Weeknumber]) && 'Date'[Weeknumber] <= 52) ||
('Date'[Weeknumber] <= MAX('Date'[Weeknumber]) && 'Date'[Weeknumber] >= 1)
)
)
)




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

Proud to be a Super User!





hi there..
Thx for the possible solution .. and it actually seems to work .. but before i accept it as solution, why the OR operator and not AND .. 
And why 52 weeks instead of 53 ??

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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