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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
joshua1990
Post Prodigy
Post Prodigy

WTD for current Week

Hello everyone!

This measure sums upp all sales for the last/ max week of selected month:

 

Sales WTD = 
CALCULATE (
    [Sales],
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Fiscal Year]
            = MAX ( 'Calendar'[Year] )
            && 'Calendar'[Date]
                <= MAX ( 'Calendar'[Date] )
            && 'Calendar'[Fiscal Month Number]
                = MAX ( 'Calendar'[Fiscal Month Number] )
            && 'Calendar'[Fis Week]
                = MAX ( 'Calendar'[Fiscal Week] )
    )
)

 

 

I would like to get the sales WTD for the current week. How is that possible?

I have a page filter for the current Fiscal Month Number.

 

Best Regards

Joshua

1 ACCEPTED SOLUTION

@joshua1990 - It might be but this is part of the reason I don't tend to use CALCULATE because it runs into difficulties once variables and stuff get involved or you start to do anything even remotely complex. Seems like maybe you could add a filter statement for that CALCULATE that did some magic I suppose using TODAY function (if that is how you define "current") so like

 

'Calendar'[Fiscal Year] = YEAR(TODAY()) for example. 

 

You can use WEEKNUM to get week number and you would also need to use WEEKDAY to get days in the week prior to the current day of the week (in order to get WTD). I've solved this whole thing a number of times in various posts but I don't do it with CALCULATE. Not saying it is impossible but I don't do things that way unless I am forced to because it is fraught with complexities.

 

Anyway, I wrote an entire blog article about why dealing with CALCULATE is a big PITA.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

@joshua1990 - Just use WEEKNUM and get everything that has the same WEEKNUM and YEAR.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler @Thanks Greg! But how? 
how would you modify the measure above to get WTD for current week? 

@joshua1990 - Well, first, I would create a "Week" column in my Calendar table. Week = WEEKNUM([Date]). Then, assuming that I have Date from Calendar in my visual I would do something like:

 

 

WTD = 
  VAR __Year = YEAR(MAX('Calendar'[Date])
  VAR __Week = MAX('Calendar'[Week])
  VAR __Weekday = WEEKDAY(MAX('Calendar'[Date]))
RETURN
  SUMX(FILTER(ALL('Sales'),YEAR('Sales'[Date])=__Year && WEEKNUM('Sales'[Date])=__Week && WEEKDAY('Sales'[Date]) <= __Weekday),[Sales])

 

Something along those lines, there's a bunch of different variations on that theme. I can think of variations using ALLEXCEPT, etc.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@joshua1990 , refer if these can help

Power BI — WTD Questions— Time Intelligence 4–5
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

WTD = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank]) && 'Date'[Weekday] <=max('Date'[Weekday])))
LWTD = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -1) && 'Date'[Weekday] <=max('Date'[Weekday])))

@joshua1990 , I suggest week rank solution as work across week solution, across the year. Also, week num can be used for WTD. Please refer to my blogs, given in my last post.

@amitchandak Thanks, but please read my post carefully.

I don't want to filter for the week. With your providied WTD measure I still have to filter for the week.

I want to get WTD for the current week without filtering anything

@amitchandak @Greg_Deckler : Guys, thank you so much!

But I am asking myself why is my approach not working?

Is there any chance to modify my approach?

I guess I need somehow to get the current week number or year-week number as a filter, right?

@joshua1990 - It might be but this is part of the reason I don't tend to use CALCULATE because it runs into difficulties once variables and stuff get involved or you start to do anything even remotely complex. Seems like maybe you could add a filter statement for that CALCULATE that did some magic I suppose using TODAY function (if that is how you define "current") so like

 

'Calendar'[Fiscal Year] = YEAR(TODAY()) for example. 

 

You can use WEEKNUM to get week number and you would also need to use WEEKDAY to get days in the week prior to the current day of the week (in order to get WTD). I've solved this whole thing a number of times in various posts but I don't do it with CALCULATE. Not saying it is impossible but I don't do things that way unless I am forced to because it is fraught with complexities.

 

Anyway, I wrote an entire blog article about why dealing with CALCULATE is a big PITA.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.