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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
tracyng0905
Frequent Visitor

Accumulate MTD Sales up to a selected date

Hi All,

I tried to create DAX to calculate the Accumulate MTD Sales up to the seleted date from Date Slicer. 

However, it cant work once I have selected a date value. 

 

tracyng0905_2-1649912333027.png

 

It works when no Date is selected:

tracyng0905_1-1649912271061.png

 

It can't work when a date is selected:

tracyng0905_3-1649912387991.png

Below 2 DAXs are tried but not work. Anyone has idea how to achieve it WITHOUT closing the interacton between the date and visual?

 

Cumulative1 =
var maxdate = Max('Date'[Date])
var mindate = Date(Year(maxdate),Month(maxdate),1)
RETURN
CALCULATE(sum(Fact[NetSales]),
ALL('Date'),
Fact[TxnDate] <= maxdate,
Filter(ALL('Date'[Date]),'Date'[Date]<=max(Fact[TxnDate]))
)
 
Cumulative2 =
var maxdate = Max('Date'[Date])
var mindate = Date(Year(maxdate),Month(maxdate),1)
RETURN
IF(CALCULATE(max('Fact'[TxnDate]),ALL('Date'[Date]))<= maxdate,
CALCULATE(sum(Fact[NetSales]),
ALL('Date'),
Filter(ALLSELECTED(Fact[TxnDate]),Fact[TxnDate]<= maxdate)
)
)

 

Here is the sample pbix: Accumulate MTD.pbix 

 

Many Thanks!

Tracy

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

A tricky game of manipulation of context,

CNENFRNL_0-1649951243241.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

5 REPLIES 5
CNENFRNL
Community Champion
Community Champion

A tricky game of manipulation of context,

CNENFRNL_0-1649951243241.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi @CNENFRNL ,
Your solution works!
It is quite interesting for the __dt part. Let me check it!

Thanks a lot!

Tracy

tracyng0905
Frequent Visitor

Hi @tamerj1 ,


It still return unexpected result when 1/2/2021 is selected:

tracyng0905_0-1649925320100.png

 

 

 

It is expected to show 3 for 1/1/2021 and 10 for 1/2/2021 when 1/2/2021 is selected. Any other idea?

 

Regards,

Tracy

tracyng0905
Frequent Visitor

Hi @tamerj1 ,


It still return unexpected result when 1/2/2021 is selected:

tracyng0905_2-1649924790731.png

 

 

It is expected to show 3 for 1/1/2021 and 10 for 1/2/2021. Any other idea?

 

Regards,

Tracy

 

 

tamerj1
Super User
Super User

Hi @tracyng0905 
You can use

Cumulative3 =
VAR maxdate =
    MAX ( 'Date'[Date] )
VAR mindate =
    DATE ( YEAR ( maxdate ), MONTH ( maxdate ), 1 )
RETURN
    CALCULATE (
        SUM ( Fact[NetSales] ),
        REMOVEFILTERS ( 'Date' ),
        'Date'[Date] > mindate,
        'Date'[Date] <= maxdate
    )

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.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.