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

help with DAX MTD

Hi there, 

I'm really struggling with this calculation with this DAX measure; What I need to accomplish is show let's sales numbers in a card. When a month is selected in another visual (like a timeline), the card should show the "sales" numbers for the selected month and that is working perfectly, what is not working is when no selection, the card should default to show "sales" for the current month, and that's is not working at all.

This is DAX I'm using right now;

 

CALCULATE(
    SUM(Fact[SALES]),
   DATESMTD(DimDate[Date])
)

Any help would be highly appreciated

 

1 ACCEPTED SOLUTION

var dt = eomonth( MAXX( summarize( fact, DimDate[Date] ), dimdate[date]), 0)

return

CALCULATE(

    SUM(Fact[SALES]),

    DATESBETWEEN( DimDate[Date], EOMONTH( dt, -1) + 1, dt )

)


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

12 REPLIES 12
bhanu_gautam
Super User
Super User

@Midway Use DAX
SalesMeasure :=
IF(
ISFILTERED(DimDate[Month]),
CALCULATE(
SUM(Fact[SALES])
),
CALCULATE(
SUM(Fact[SALES]),
DATESMTD(DimDate[Date])
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






techies
Super User
Super User

Hi @Midway please check this

 

ResultMeasure=

VAR IsMonthSelected = ISFILTERED('DATE'[Month])

VAR DefaultMonthSales =
CALCULATE(
SUM('sheet1'[enrollment amount]),
FILTER(
ALL('DATE'),
'DATE'[Year] = YEAR(TODAY()) && 'DATE'[Month] = MONTH(TODAY())
)
)

VAR SelectedMonthSales =
CALCULATE(
SUM('sheet1'[enrollment amount]),
DATESMTD('DATE'[Date])
)

RETURN
IF(
IsMonthSelected,
SelectedMonthSales,
DefaultMonthSales
)

― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

Thanks for replying to my post, this gets the default sales numbers for the current month when no selection has been made, but it keeps the same current month sales numbers when selecting other months.

Pow3Range
Frequent Visitor

UPDATED 
-------
VAR DATE_ =
IF(
ISFILTERED(DimDate[Date]),
MAX(DimDate[Date]),
TODAY()
)
RETURN
CALCULATE(
SUM(Fact[SALES]),
DATESBETWEEN(DimDate[Date], EOMONTH(DATE_, -1) + 1, EOMONTH(DATE_, 0))
)

Thanks for replying to my post, this gets the default sales numbers for the current month when no selection has been made, but it keeps the same current month sales numbers when selecting other months.

Deku
Super User
Super User

var dt = max( DimDate[Date] )
return
CALCULATE(
    SUM(Fact[SALES]),
    KEEPFILTERS( DATESBETWEEN( DimDate[Date], EOMONTH( dt, -1) + 1, dt ), dt ) )
)

Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

hey there, thanks for replying to my post. I tried this formula but it's giving an error, "unexpected parameter , dt". If I remove runs fine but still does not work. Still no sales without selecting any data points.

Where is it complaining?


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Updated

var dt = MAX( DimDate[Date] )
return
CALCULATE(
    SUM(Fact[SALES]),
    DATESBETWEEN( DimDate[Date], EOMONTH( dt, -1) + 1, dt )
)

Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

it works when selecting any month but it's not defaulting to show current month sales when there is no selection.

var dt = eomonth( MAXX( summarize( fact, DimDate[Date] ), dimdate[date]), 0)

return

CALCULATE(

    SUM(Fact[SALES]),

    DATESBETWEEN( DimDate[Date], EOMONTH( dt, -1) + 1, dt )

)


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Thansk very much Deku!! this did the trick!

 

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.