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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

MTD Changes over selected month

I am trying following dax for current month MTD but I am getting trouble when selecting other months.

 

MTD Purchase count-

IF (
DAY ( TODAY () ) = 1 && MONTH(TODAY())=1,
CALCULATE (
DISTINCTCOUNT(tracksales[MobileNumber]),
DATESBETWEEN (
DimDate[FullDateAlternateKey],
DATE ( YEAR ( TODAY () )-1, 12, 1 ),
DATE ( YEAR ( TODAY () )-1, MONTH ( TODAY () )-1, DAY(EOMONTH(TODAY()-1,0)))
)
),
IF (
DAY ( TODAY () ) = 1,
CALCULATE (
DISTINCTCOUNT(tracksales[MobileNumber]),
DATESBETWEEN (
DimDate[FullDateAlternateKey],
DATE ( YEAR ( TODAY () ), MONTH ( TODAY () )-1, 1 ),
DATE ( YEAR ( TODAY () ), MONTH ( TODAY () )-1, DAY(EOMONTH(TODAY()-1,0)))
)
),
CALCULATE (DISTINCTCOUNT(tracksales[MobileNumber])
,
DATESBETWEEN (
DimDate[FullDateAlternateKey],
DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ),
TODAY () -1
)
)
))
 
 
and then i am using following dax for toggle-
 
MTD  Purchase =
IF (
ISCROSSFILTERED ( 'Counts/volume'[UNITS/VOLUME]) ,
IF(
SELECTEDVALUE( 'Counts/volume'[UNITS/VOLUME])="VOLUME"
,[MTD purchase Volume],
if(
SELECTEDVALUE( 'Counts/volume'[UNITS/VOLUME])="UNITS"
,[MTD purchase Count]
))
,[MTD purchase Count]
)
 
so please help me to make this dynamic.
1 REPLY 1
Anonymous
Not applicable

@Anonymous 

 

Please do not try to re-invent the wheel. Use the tried and tested techniques that use the in-built time intelligence. Also, interleaving code with TODAY() is making your code rigid. By doing that you are making sure that the code will not be flexible. Here's something to get you started on your way to the correct solution: Time Intelligence in Power BI Desktop - SQLBI

 

Use the Search capability of the above site to look for things of interest.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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.