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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
pferban
New Member

Measures with Weeknum for past (1,2,3,4,5) weeks

Hi, and happy new year!!

 

I have 5 measurements to calculate the sum for:

This week
This week -1
This week -2
This week -3
This week -4
This week -5

With the change of year, the formula no longer works. This is the formula used by subtracting the necessary weeks in each measure:

=CALCULATE(SUM(QTY);FILTER(TABLE,WEEKNUM(TABLE.DATE;2)=WEEKNUM(TODAY();2)-1))

 

WEEKNUM(TODAY();2) = 2

WEEKNUM(TODAY();2)-1= 1

WEEKNUM(TODAY();2)-2=0

...

 

I need:

WEEKNUM(TODAY();2) -2 = 53

 

Do you know any solution?
Thank you

2 REPLIES 2
AlB
Super User
Super User

Hi @pferban 

The easiest would be to create an additional column on your date table that has the weeknumber across years.  Then you can use that column to find all those weeks by just subtracting 1, 2, etc.  One option:

WeekyNumGlobal =
CALCULATE (
    DISTINCTCOUNT ( DateT[Weeknumber] ),
    DateT[Date] <= EARLIER ( DateT[Date] ),
    ALL ( DateT )
)

This assumes you have a WeekNumber column in your date already. Create it if you do not

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Cheers 

 

SU18_powerbi_badge

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors