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
Anonymous
Not applicable

DAX HELP

i am creating a calculated column 
i have mtd ,ytd qtd  mtd today -1 i want IF A NEW YEAR STARTS THEN MTD SHOULD SHOW LAST MONTH 1 ST TO 31SR AND SAME LIKE QTD WHEN NEW QUATER STARTS SAME PERVOIUS QUATER TO START TILL 31SR DEC  ,SAME LIKE YTD IF DAY =1 JAN JAN 1ST 2025 A NEW YEAR START YTS ALSO SOULD SHOW  1 JAN 2024 TO 31-DEC-2024 

ANY ONE HELP ME 

1 ACCEPTED SOLUTION
v-jiewu-msft
Community Support
Community Support

Hi @Anonymous ,

Please try the following methods and check if they can solve your problem:

1.Create the simple table.

vjiewumsft_0-1708680006390.png

2.Create the new measure to calculate MTD. Drag the measure into the Filter and edit the items is 1.

 

MTD = 
VAR start_month = EOMONTH(DATE(2025,1,1), -2) + 1
var end_month = EOMONTH(DATE(2025,1,1), -1)
RETURN
    IF(MONTH(MAX([Date])) = 12, 1, 0
    )

 

vjiewumsft_1-1708680024694.png

3.Create the new measure to calculate YTD. Drag the measure into the Filter and edit the items is 1.

 

YTD = 
var year_start = DATE(YEAR(2025) - 1, 1, 1)
VAR year_end = DATE(YEAR(2025) - 1, 12, 31)
RETURN
IF(YEAR(MAX(DateTable[Date])) = 2024, 1, 0)

 

 

4.Create the new measure to calculate QTD. Drag the measure into the Filter and edit the items is 1.

 

QTD = 
VAR current_quarter = QUARTER(1)
VAR end_month = IF(current_quarter = 1, 12, (current_quarter - 1) * 3)
VAR start_month = end_month - 2
RETURN
    IF(QUARTER(MAX(DateTable[Date])) = 4, 1, 0)

 

5.The result is shown below for MTD.

vjiewumsft_2-1708680124567.png

 

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
v-jiewu-msft
Community Support
Community Support

Hi @Anonymous ,

Please try the following methods and check if they can solve your problem:

1.Create the simple table.

vjiewumsft_0-1708680006390.png

2.Create the new measure to calculate MTD. Drag the measure into the Filter and edit the items is 1.

 

MTD = 
VAR start_month = EOMONTH(DATE(2025,1,1), -2) + 1
var end_month = EOMONTH(DATE(2025,1,1), -1)
RETURN
    IF(MONTH(MAX([Date])) = 12, 1, 0
    )

 

vjiewumsft_1-1708680024694.png

3.Create the new measure to calculate YTD. Drag the measure into the Filter and edit the items is 1.

 

YTD = 
var year_start = DATE(YEAR(2025) - 1, 1, 1)
VAR year_end = DATE(YEAR(2025) - 1, 12, 31)
RETURN
IF(YEAR(MAX(DateTable[Date])) = 2024, 1, 0)

 

 

4.Create the new measure to calculate QTD. Drag the measure into the Filter and edit the items is 1.

 

QTD = 
VAR current_quarter = QUARTER(1)
VAR end_month = IF(current_quarter = 1, 12, (current_quarter - 1) * 3)
VAR start_month = end_month - 2
RETURN
    IF(QUARTER(MAX(DateTable[Date])) = 4, 1, 0)

 

5.The result is shown below for MTD.

vjiewumsft_2-1708680124567.png

 

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

have several time-based metrics such as MTD (Month-to-Date), YTD (Year-to-Date), and QTD (Quarter-to-Date). For the MTD calculation, I want it to show data from the 1st to the last day of the previous month if the current date is the 1st day of a new year. Similarly, for QTD, I need it to display data from the start of the previous quarter until December 31st if a new quarter starts. Additionally, for YTD, when it's January 1st of a new year, I'd like it to show data from January 1st of the previous year to December 31st of the previous year.

Could you please assist me in rewriting the logic for this calculated column?

Thank you very much for your help!

 

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.