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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.