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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Kalyani2009
Regular Visitor

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

@Kalyani2009 

 

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors