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
ErikBe
Frequent Visitor

Calculating MTD value from YTD values

Hi,

 

I have a data table with only YTD sales value, by month, and would like to calculate the MTD values. Being a PowerBi beginner I cannot figure out how to get this done and when searching the forum for clues, all I found was answers on how to solve the opposite problem, i.e.  calculating MTD/QTD/YTD etc from daily or monthly figures.

 

Below is a sample table of how the data looks and fyi, I managed to create a date_table which I guess comes in handy here.

 

Month (YYYY-MM)YTD SalesMTD Sales

2019-12

1000?

2020-01

100?
2020-02300?
2020-03500?
2020-04900?

 

I appreciate any support!

 

Stay safe,

Erik 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@ErikBe,

Try this calculated column. I recommend a calculated column instead of a measure, because having MTD in a column will allow you to perform various time intelligence calculations.

MTD Sales =
VAR vDate = YTDtoMTD[Month Ending]
VAR vPrevDate =
    CALCULATE (
        MAX ( YTDtoMTD[Month Ending] ),
        ALL ( YTDtoMTD ),
        YTDtoMTD[Month Ending] < vDate
    )
VAR vPrevSales =
    CALCULATE (
        SUM ( YTDtoMTD[YTD Sales] ),
        ALL ( YTDtoMTD ),
        YTDtoMTD[Month Ending] = vPrevDate
    )
VAR vYTD = YTDtoMTD[YTD Sales]
VAR vMTD = vYTD - vPrevSales
VAR vResult =
    IF ( MONTH ( vDate ) = 1, vYTD, vMTD )
RETURN
    vResult

DataInsights_0-1607807994281.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

@ErikBe,

Try this calculated column. I recommend a calculated column instead of a measure, because having MTD in a column will allow you to perform various time intelligence calculations.

MTD Sales =
VAR vDate = YTDtoMTD[Month Ending]
VAR vPrevDate =
    CALCULATE (
        MAX ( YTDtoMTD[Month Ending] ),
        ALL ( YTDtoMTD ),
        YTDtoMTD[Month Ending] < vDate
    )
VAR vPrevSales =
    CALCULATE (
        SUM ( YTDtoMTD[YTD Sales] ),
        ALL ( YTDtoMTD ),
        YTDtoMTD[Month Ending] = vPrevDate
    )
VAR vYTD = YTDtoMTD[YTD Sales]
VAR vMTD = vYTD - vPrevSales
VAR vResult =
    IF ( MONTH ( vDate ) = 1, vYTD, vMTD )
RETURN
    vResult

DataInsights_0-1607807994281.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you very much @DataInsights 

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.