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
batman
Helper I
Helper I

DAX WTD HELP

Greetings everyone,

I require some help with DAX. I am currently displaying the Year, Week, and Date in a Matrix Table, allowing for drill-down functionality. I am in need of writing a calculation for a Measure that accumulates values and resets every week. It's important to note that my week starts on Monday. Below is the measure I have written for the current year. In the second column, I need a calculation that represents the same value for the prior year. I would greatly appreciate any assistance or guidance provided. Thank you in advance.

 

WTD CY = CALCULATE(sum(Tab1[Dollars]), FILTER(ALL('Calendar'),'Calendar'[Week Rank]=max('Calendar'[Week Rank]) && 'Calendar'[Weekday] <=max('Calendar'[Weekday])))

 
Additionally, I have created some additional measures for testing purposes. However, I have encountered an issue where these measures do not apply the desired filters when modifications are made on a slicer.

DOL WTD =
VAR CurrentDate = LASTDATE('Calendar'[Date])
VAR DayNumberOfWeek = 'Calendar'[Day Number of Week for Date]
RETURN
    CALCULATE(
        SUM ( Tab1[Dollars]),
        DATESBETWEEN(
            'Calendar'[Date],
            DATEADD(
                CurrentDate,
                -1 * (DayNumberOfWeek - 1),
                DAY
            ),
            CurrentDate
        )
    )


and 

DOL WTD LY =
VAR CurrentDate = LASTDATE('Calendar'[Date])
VAR DayNumberOfWeek = WEEKDAY(CurrentDate, 2)
VAR StartDate = DATEADD(
                    CurrentDate,
                    -1 * (DayNumberOfWeek - 1),
                    DAY
                )
VAR StartDateLY = DATEADD(
                      StartDate,
                      -364,
                      DAY
                  )
RETURN
    CALCULATE(
        SUM(Tab1[Dollars]),
        FILTER(
            ALL('Calendar'),
            'Calendar'[Date] >= StartDateLY && 'Calendar'[Date] <= DATEADD(CurrentDate, -364, DAY)
        )
    )


Thanks once again
 
B
5 REPLIES 5
batman
Helper I
Helper I

Thank you guys, much appreciated.

jiaopengzi
Frequent Visitor

The meaning of wtd is roughly as follows, please refer to it.

 

```

VAR DATE_END_AC =
LASTDATE ( '01_Calendar'[dates] )
VAR N_W =
WEEKDAY ( DATE_END_AC, 3 ) // Monday:0,Sunday:6
VAR DATE_START_AC =
DATEADD ( DATE_END_AC, - N_W, DAY )
VAR DATE_TABLE_AC =
DATESBETWEEN ( '01_Calendar'[dates], DATE_START_AC, DATE_END_AC )
VAR WTD0 =
CALCULATE ( SELECTEDMEASURE (), DATE_TABLE_AC )
```

 

There are more time dimensions, see the picture below.

 

jiaopengzi_2-1684371365944.png

 

https://jiaopengzi.com/2653.html

 

 

 

Is there an English version of this? 

amitchandak
Super User
Super User

@batman , have column year, week, and weekday. try like

 

WTD LY = CALCULATE(sum(Tab1[Dollars]), FILTER(ALL('Calendar'),'Calendar'[Year]=max('Calendar'[Year]) -1   && 'Calendar'[Week]=max('Calendar'[Week]) && 'Calendar'[Weekday] <=max('Calendar'[Weekday])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak - Thank you for providing feedback, I was able to make it work with a similar formula 

DOLLARS WTD LY = CALCULATE(
  sum(Tab1[Dollars]),
  FILTER(
    ALL('Calendar'),
    'Calendar'[Week Rank] = max('Calendar'[Week Rank]) - 52
    && 'Calendar'[Weekday] <= max('Calendar'[Weekday])
  )
)


However once I roll it up to yearly level it just take the last number of the last week. Have you ran into this challange before? 

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.