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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Arthur94
Regular Visitor

DAX how to write - Monthly total appear in the first week

Hello everyone,

 

Intro: Im new comer to dax and encounter a problem in dax. Really appreciate your help!

 

Problem description:

1. Monthly subtotal appear only in the first week

2. That subtotal "can be" accumulative

 

Simplified Example:

MonthWeekDateSalesMonth Total (What i want)Cumulative Month Total (What i want)
Jan12023-01-0152525
Jan22023-01-085025
Jan32023-01-155025
Jan42023-01-225025
Jan52023-01-295025
Feb12023-02-0552045
Feb22023-02-125045
Feb32023-02-195045
Feb42023-02-265045

 

The codes I write:

1. Month Total=

IF(MIN([WEEK])=1,

CALCULATE([Sales], ALLEXCEPT([Month]),

0)

 

2. Cumulative Month Total=

CALCULATE([Month Total], FILTER(ALL(Calendar),Calendar[Date]<=MAX(Calendar[Date])))

 

Result:
For the 1st code, i get what I want. But for the 2nd code its not working.

 

Can anyone help! Thx!!!

Arthur

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Arthur94 ,

 

I suggest you to create a calendar table with [YearMonth] column.

Calendar = 
ADDCOLUMNS (
    CALENDARAUTO (),
    "Year", YEAR ( [Date] ),
    "MonthNum", MONTH ( [Date] ),
    "Month", FORMAT ( [Date], "MMM" ),
    "WeekStart",
        [Date] - WEEKDAY ( [Date], 1 ) + 1,
    "YearMonth",
        YEAR ( [Date] ) * 100
            + MONTH ( [Date] )
)

vrzhoumsft_0-1679906950631.png

Measure:

Cumulative Month Total = 
CALCULATE (
    [Month Total],
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[YearMonth] <= MAX ( 'Calendar'[YearMonth] )
    )
)

Result is as below.

vrzhoumsft_1-1679906979467.png

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Arthur94
Regular Visitor

Sorry for the table format. Realized the date and sales are to close after posted. Sales are 5 for each week.

Anonymous
Not applicable

Hi @Arthur94 ,

 

I suggest you to create a calendar table with [YearMonth] column.

Calendar = 
ADDCOLUMNS (
    CALENDARAUTO (),
    "Year", YEAR ( [Date] ),
    "MonthNum", MONTH ( [Date] ),
    "Month", FORMAT ( [Date], "MMM" ),
    "WeekStart",
        [Date] - WEEKDAY ( [Date], 1 ) + 1,
    "YearMonth",
        YEAR ( [Date] ) * 100
            + MONTH ( [Date] )
)

vrzhoumsft_0-1679906950631.png

Measure:

Cumulative Month Total = 
CALCULATE (
    [Month Total],
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[YearMonth] <= MAX ( 'Calendar'[YearMonth] )
    )
)

Result is as below.

vrzhoumsft_1-1679906979467.png

Best Regards,
Rico Zhou

 

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

Hi Rico,

 

I used your code in my data model. That solved my problem.

Thank you so much. Very helpful!!!😁

Arthur

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.