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

How can I calcurate MTD based on accounting month?

Hi, please let me know how to find correct figure of MTD.


What I want to find is..

    - sales mtd during account period which does not start from 1st of month.

       e.g. November : start from Mon, 28 Oct 2019, end on Sun 24 Nov 2019

    - If possible I want someone to collect the measure I made, otherwise please let me know best way.

 

What I confuse is..

    - I can't use TOTALMTD due to it dosen't start from 1st of month
    - I made three measures named First_AMonth, LastDate_Amonth, Sales MTD.
    First_AMonth and "LastDate_Amonth" work properly indivisually but doesn't work in Sales MTD.


Name of Table & Measure
-------------------------------------

    Sales[Sales]

    Sales_Calc[Sales MTD],[First_AMonth],[LastDate_Amonth]

    Calendar_lookup

calendar.png

 

Measure
-------------------------------------

Sales MTD =
    CALCULATE(
       sum(Sales[Sales]),
       FILTER(
           All(Calendar_lookup),
          Calendar_lookup[date] >= Sales_Calc[First_AMonth] && Calendar_lookup[Date] < Sales_Calc[LastDate_Amonth]
       )
    )

 

First_AMonth =
    CALCULATE(
       min(Calendar_lookup[Date]),
       Filter(
          ALL(Calendar_lookup),
          Calendar_lookup[Accounting Month]= SELECTEDVALUE(Calendar_lookup[Accounting Month]) &&
          Calendar_lookup[Accounting Year]= SELECTEDVALUE(Calendar_lookup[Year])
       )
    )


LastDate_Amonth =
    CALCULATE(
       Max(Calendar_lookup[Date]),
       Filter(
          ALL(Calendar_lookup),
          Calendar_lookup[Year] = SELECTEDVALUE(Calendar_lookup[Year])
          && Calendar_lookup[Accounting Month] = SELECTEDVALUE(Calendar_lookup[Accounting Month])
          && Calendar_lookup[Week of Year]=SELECTEDVALUE(Calendar_lookup[Week of Year])
       )
    )

 

 

Report image

report_image.png

 


I hope your kind support.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

It's better to have sample data, just a small part for testing. I think if First_AMonth and LastDate_Amonth work well, maybe you can try to use these two measures as variables in Sales MTD, similar to the following:

Sales MTD =
VAR _First_AMonth =
    CALCULATE (
        MIN ( Calendar_lookup[Date] ),
        FILTER (
            ALL ( Calendar_lookup ),
            Calendar_lookup[Accounting Month]
                = SELECTEDVALUE ( Calendar_lookup[Accounting Month] )
                && Calendar_lookup[Accounting Year] = SELECTEDVALUE ( Calendar_lookup[Year] )
        )
    )
VAR _LastDate_Amonth =
    CALCULATE (
        MAX ( Calendar_lookup[Date] ),
        FILTER (
            ALL ( Calendar_lookup ),
            Calendar_lookup[Year] = SELECTEDVALUE ( Calendar_lookup[Year] )
                && Calendar_lookup[Accounting Month]
                    = SELECTEDVALUE ( Calendar_lookup[Accounting Month] )
                && Calendar_lookup[Week of Year] = SELECTEDVALUE ( Calendar_lookup[Week of Year] )
        )
    )
RETURN
    CALCULATE (
        SUM ( Sales[Sales] ),
        FILTER (
            ALL ( Calendar_lookup ),
            Calendar_lookup[date] >= _First_AMonth
                && Calendar_lookup[Date] < _LastDate_Amonth
        )
    )

Best Regards,
Community Support Team _ Joey
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

5 REPLIES 5
amitchandak
Super User
Super User

If possible please share a sample pbix file after removing sensitive information.
Thanks

Anonymous
Not applicable

Hi @amitchandak, thank you for reply.

I am ready for data but unfortunately I can't share the file as I am not allowed to share via other sharing service and I can't attach this post neither. The data is simply made as below.

11.png12.png13.png

 

as result

Sales MTD shows wrong number;

In this case it should be shown 56000 on Sales MTD for shop1 as it is choosen first week by slicer.)

 

10.png

 

Hi @Anonymous ,

It's better to have sample data, just a small part for testing. I think if First_AMonth and LastDate_Amonth work well, maybe you can try to use these two measures as variables in Sales MTD, similar to the following:

Sales MTD =
VAR _First_AMonth =
    CALCULATE (
        MIN ( Calendar_lookup[Date] ),
        FILTER (
            ALL ( Calendar_lookup ),
            Calendar_lookup[Accounting Month]
                = SELECTEDVALUE ( Calendar_lookup[Accounting Month] )
                && Calendar_lookup[Accounting Year] = SELECTEDVALUE ( Calendar_lookup[Year] )
        )
    )
VAR _LastDate_Amonth =
    CALCULATE (
        MAX ( Calendar_lookup[Date] ),
        FILTER (
            ALL ( Calendar_lookup ),
            Calendar_lookup[Year] = SELECTEDVALUE ( Calendar_lookup[Year] )
                && Calendar_lookup[Accounting Month]
                    = SELECTEDVALUE ( Calendar_lookup[Accounting Month] )
                && Calendar_lookup[Week of Year] = SELECTEDVALUE ( Calendar_lookup[Week of Year] )
        )
    )
RETURN
    CALCULATE (
        SUM ( Sales[Sales] ),
        FILTER (
            ALL ( Calendar_lookup ),
            Calendar_lookup[date] >= _First_AMonth
                && Calendar_lookup[Date] < _LastDate_Amonth
        )
    )

Best Regards,
Community Support Team _ Joey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @v-joesh-msft,

Thank you for your detail explanation and now it works completely!!

I had been tried such lots of parturns and been failed to get correct figure due to filter interfering with each other.

Now it is sorted and I've learned so good knowledge from you!

 

Thanks again Joey!

Anonymous
Not applicable

Please find original data (image) of customer, sales as well.

customercustomerSalesSales

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.