cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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

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.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors