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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Dax for previous date calculations

Hi,

 

I have a week ending date column and starts revenue in my report.

neelofarshama_0-1614254984646.png

I have to build a report which shows 

How many starts last week compared to the previous week, previous month, previous year , like shown below

3.PNG

 

 

How many starts last month compared to the previous month, previous year

4.PNG

How many starts last year compared to the previous year

How many starts last week compared to the cumulative starts for the same period of the previous year

 
 

Can you please help me how to create the DAX for the above requirement as I have weekending column as date column.

 

Thanks & Regards,

Neelofar Shama.

 

2 ACCEPTED SOLUTIONS
DataZoe
Microsoft Employee
Microsoft Employee

@Anonymous For this type of time intelligence a date table will make your life a bit easier 🙂  I have the last week, last month, and last year of the weekly amounts created for you in the attached PBIX. Once you have a date table, the measures can be created.

DataZoe_0-1614273420695.png

 

Date table I used, (Modeling --> New Table):

 

Date =
ADDCOLUMNS (
CALENDAR (
DATE ( YEAR ( MIN ( 'Table'[WEEK_ENDING] ) ), 1, 1 ),
DATE ( YEAR ( MAX ( 'Table'[WEEK_ENDING] ) ), 12, 31 )
),
"Month", DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 ),
"Year", DATE ( YEAR ( [Date] ), 1, 1 ),
"WeekOf",
[Date] - WEEKDAY ( [Date], 1 ) + 1,
"Monthly Week Number",
WEEKNUM ( [Date], 1 )
- WEEKNUM ( DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 ), 1 ) + 1,
"Yearly Week Number", WEEKNUM ( [Date] )
)

 

and the measures:

Total Starts = sum('Table'[STARTS])
 
Last Week =
VAR lw =
SELECTEDVALUE ( 'Date'[Date] ) - 7
RETURN
IF ( ISBLANK ( lw ), BLANK (), CALCULATE ( [Total Starts], 'Date'[Date] = lw ) )
 
Last Month =
VAR wn =
SELECTEDVALUE ( 'Date'[Monthly Week Number] )
RETURN
IF (
OR ( ISBLANK ( wn ), ISBLANK ( [Total Starts] ) ),
BLANK (),
CALCULATE (
[Total Starts],
PREVIOUSMONTH ( 'Date'[Date] ),
'Date'[Monthly Week Number] = wn
)
)
 
Last Year =
VAR wn =
SELECTEDVALUE ( 'Date'[Yearly Week Number] )
RETURN
IF (
OR ( ISBLANK ( wn ), ISBLANK ( [Total Starts] ) ),
BLANK (),
CALCULATE (
[Total Starts],
PREVIOUSYEAR ( 'Date'[Date] ),
'Date'[Yearly Week Number] = wn
)
)
 
Hope this helps!

 

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

Icey
Community Support
Community Support

Hi @Anonymous ,

 

If you don't want to create a calendar table, you can try this:

Week Number = WEEKNUM(MAX('Table'[WEEK_ENDING]),2)
Month WeekNum = 
VAR CurrentWeekEnding = MAX ( 'Table'[WEEK_ENDING] )
RETURN
WEEKNUM ( CurrentWeekEnding, 2 )
    - WEEKNUM (
        DATE ( YEAR ( CurrentWeekEnding ), MONTH ( CurrentWeekEnding ), 1 ),
        2
    ) + 1
Last Week STARTS = 
SUMX (
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[WEEK_ENDING]
            = MAX ( 'Table'[WEEK_ENDING] ) - 7
    ),
    [STARTS]
)
Last Month STARTS = 
VAR CurrentMonthWeekNum = [Month WeekNum]
VAR CurrentWeekEnding =
    MAX ( 'Table'[WEEK_ENDING] )
VAR CurrentYear =
    YEAR ( CurrentWeekEnding )
VAR CurrentMonth =
    MONTH ( CurrentWeekEnding )
RETURN
    SWITCH (
        CurrentMonth,
        1,
            SUMX (
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[WEEK_ENDING] ) = CurrentYear - 1
                        && MONTH ( 'Table'[WEEK_ENDING] ) = 12
                        && [Month WeekNum] = CurrentMonthWeekNum
                ),
                [STARTS]
            ),
        SUMX (
            FILTER (
                ALLSELECTED ( 'Table' ),
                YEAR ( 'Table'[WEEK_ENDING] ) = CurrentYear
                    && MONTH ( 'Table'[WEEK_ENDING] ) = CurrentMonth - 1
                    && [Month WeekNum] = CurrentMonthWeekNum
            ),
            [STARTS]
        )
    )
Last Year STARTS = 
VAR CurrentYearWeekNum = [Week Number]
VAR CurrentWeekEnding =
    MAX ( 'Table'[WEEK_ENDING] )
VAR CurrentYear =
    YEAR ( CurrentWeekEnding )
VAR CurrentMonth =
    MONTH ( CurrentWeekEnding )
RETURN
SUMX (
            FILTER (
                ALLSELECTED ( 'Table' ),
                YEAR ( 'Table'[WEEK_ENDING] ) = CurrentYear-1
                    && [Week Number] = CurrentYearWeekNum
            ),
            [STARTS]
        )

starts.JPG

 

 

Best Regards,

Icey

 

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

2 REPLIES 2
Icey
Community Support
Community Support

Hi @Anonymous ,

 

If you don't want to create a calendar table, you can try this:

Week Number = WEEKNUM(MAX('Table'[WEEK_ENDING]),2)
Month WeekNum = 
VAR CurrentWeekEnding = MAX ( 'Table'[WEEK_ENDING] )
RETURN
WEEKNUM ( CurrentWeekEnding, 2 )
    - WEEKNUM (
        DATE ( YEAR ( CurrentWeekEnding ), MONTH ( CurrentWeekEnding ), 1 ),
        2
    ) + 1
Last Week STARTS = 
SUMX (
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[WEEK_ENDING]
            = MAX ( 'Table'[WEEK_ENDING] ) - 7
    ),
    [STARTS]
)
Last Month STARTS = 
VAR CurrentMonthWeekNum = [Month WeekNum]
VAR CurrentWeekEnding =
    MAX ( 'Table'[WEEK_ENDING] )
VAR CurrentYear =
    YEAR ( CurrentWeekEnding )
VAR CurrentMonth =
    MONTH ( CurrentWeekEnding )
RETURN
    SWITCH (
        CurrentMonth,
        1,
            SUMX (
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[WEEK_ENDING] ) = CurrentYear - 1
                        && MONTH ( 'Table'[WEEK_ENDING] ) = 12
                        && [Month WeekNum] = CurrentMonthWeekNum
                ),
                [STARTS]
            ),
        SUMX (
            FILTER (
                ALLSELECTED ( 'Table' ),
                YEAR ( 'Table'[WEEK_ENDING] ) = CurrentYear
                    && MONTH ( 'Table'[WEEK_ENDING] ) = CurrentMonth - 1
                    && [Month WeekNum] = CurrentMonthWeekNum
            ),
            [STARTS]
        )
    )
Last Year STARTS = 
VAR CurrentYearWeekNum = [Week Number]
VAR CurrentWeekEnding =
    MAX ( 'Table'[WEEK_ENDING] )
VAR CurrentYear =
    YEAR ( CurrentWeekEnding )
VAR CurrentMonth =
    MONTH ( CurrentWeekEnding )
RETURN
SUMX (
            FILTER (
                ALLSELECTED ( 'Table' ),
                YEAR ( 'Table'[WEEK_ENDING] ) = CurrentYear-1
                    && [Week Number] = CurrentYearWeekNum
            ),
            [STARTS]
        )

starts.JPG

 

 

Best Regards,

Icey

 

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

DataZoe
Microsoft Employee
Microsoft Employee

@Anonymous For this type of time intelligence a date table will make your life a bit easier 🙂  I have the last week, last month, and last year of the weekly amounts created for you in the attached PBIX. Once you have a date table, the measures can be created.

DataZoe_0-1614273420695.png

 

Date table I used, (Modeling --> New Table):

 

Date =
ADDCOLUMNS (
CALENDAR (
DATE ( YEAR ( MIN ( 'Table'[WEEK_ENDING] ) ), 1, 1 ),
DATE ( YEAR ( MAX ( 'Table'[WEEK_ENDING] ) ), 12, 31 )
),
"Month", DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 ),
"Year", DATE ( YEAR ( [Date] ), 1, 1 ),
"WeekOf",
[Date] - WEEKDAY ( [Date], 1 ) + 1,
"Monthly Week Number",
WEEKNUM ( [Date], 1 )
- WEEKNUM ( DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 ), 1 ) + 1,
"Yearly Week Number", WEEKNUM ( [Date] )
)

 

and the measures:

Total Starts = sum('Table'[STARTS])
 
Last Week =
VAR lw =
SELECTEDVALUE ( 'Date'[Date] ) - 7
RETURN
IF ( ISBLANK ( lw ), BLANK (), CALCULATE ( [Total Starts], 'Date'[Date] = lw ) )
 
Last Month =
VAR wn =
SELECTEDVALUE ( 'Date'[Monthly Week Number] )
RETURN
IF (
OR ( ISBLANK ( wn ), ISBLANK ( [Total Starts] ) ),
BLANK (),
CALCULATE (
[Total Starts],
PREVIOUSMONTH ( 'Date'[Date] ),
'Date'[Monthly Week Number] = wn
)
)
 
Last Year =
VAR wn =
SELECTEDVALUE ( 'Date'[Yearly Week Number] )
RETURN
IF (
OR ( ISBLANK ( wn ), ISBLANK ( [Total Starts] ) ),
BLANK (),
CALCULATE (
[Total Starts],
PREVIOUSYEAR ( 'Date'[Date] ),
'Date'[Yearly Week Number] = wn
)
)
 
Hope this helps!

 

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.