Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

How we can create YTD numbers by using MTD

Hi Guys,

I have MTD sales monthly wise. i need to create YTD numbers.

 

For Ex: Jan-20 = 100, Feb-20 = 150

           Jan-20 = 31 days ,Feb-20 =29 days

 

now, my Feb20 - YTD formula will be ==> (Jan-20*jan-20 days + feb-20*feb-20 days) / (Jan-20days + Feb-20 days)

                                                           ==>  (100*31 + 150*29) / (31+29) = 124.16

 

  Mar20 - YTD formula will be ==>

                 (Jan-20*jan-20 days + feb-20*feb-20 days+ mar-20*mar-20 days ) / (Jan-20days+Feb-20 days+Mar-20days)

 

can please help me how we can write dax expression on this requirment.

 

regards,

som

 

  • Hi, Anonymous 

    According to your description and sample expressions, I can understand what you want to get, I created some data and achieve the result using DAX, you can take a look and find if it’s useful:

    This is my test data:

     

    1. I created these calculated columns:
    monthdays =
    
    DATEDIFF(DATE(YEAR([Date]),MONTH([Date]),1),EOMONTH('Table'[Date],0),DAY)+1
    Value1 =
    
    [Value]*[monthdays]
    Rolling1 =
    
    CALCULATE(SUM([Value1]),FILTER(ALLSELECTED('Table'),[Date]<=EARLIER([Date])))
    Rolling2 =
    
    CALCULATE(SUM([monthdays]),FILTER(ALLSELECTED('Table'),[Date]<=EARLIER([Date])))
    YTD =
    
    DIVIDE([Rolling1],[Rolling2])
    1. Then I created a table chart and place like this:

     

    And you can get what you want.

    You can download my test pbix file here

     

    If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

    How to Get Your Question Answered Quickly 

     

    Best Regards,

    Community Support Team _Robert Qin

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

1 Reply

  • v-robertq-msft's avatar
    v-robertq-msft
    Icon for Community Support rankCommunity Support

    Hi, Anonymous 

    According to your description and sample expressions, I can understand what you want to get, I created some data and achieve the result using DAX, you can take a look and find if it’s useful:

    This is my test data:

     

    1. I created these calculated columns:
    monthdays =
    
    DATEDIFF(DATE(YEAR([Date]),MONTH([Date]),1),EOMONTH('Table'[Date],0),DAY)+1
    Value1 =
    
    [Value]*[monthdays]
    Rolling1 =
    
    CALCULATE(SUM([Value1]),FILTER(ALLSELECTED('Table'),[Date]<=EARLIER([Date])))
    Rolling2 =
    
    CALCULATE(SUM([monthdays]),FILTER(ALLSELECTED('Table'),[Date]<=EARLIER([Date])))
    YTD =
    
    DIVIDE([Rolling1],[Rolling2])
    1. Then I created a table chart and place like this:

     

    And you can get what you want.

    You can download my test pbix file here

     

    If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

    How to Get Your Question Answered Quickly 

     

    Best Regards,

    Community Support Team _Robert Qin

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