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

4 Years MAT calculation with YOY change

Hello everyone,

 

I have just started POWER BI and struggling to find a solution for moving annual total.

 

I currently have over 4 years of data from (01 Jan 2016 to 30 Jul 2021). and I would like to compare the last 4 MAT; 

  • MAT Jul 2021 (Aug 20 to Jul 2021)
  • MAT Jul 2020 (Aug 19 to Jul 2020)
  • MAT Jul 2019 (Aug 18 to Jul 2019)
  • MAT Jul 2018 (Aug 17 to Jul 2018)

Since 2021 isn't finished, every time I do YOY% calculation, the 2021 % will be down by 40%. 

 

How do I go about solving this issue to only compare the same period in the previous years? As the year progress, there will be more monthly data i.e. MAT Jul 2021 becomes MAT August 2021 once August data become available?

 

Is it best to build a MAT period in the calendar table or by DAX during calculation? Could someone please kindly guide me on this?

 

1 ACCEPTED SOLUTION
ERD
Super User
Super User

Hi @enghone09 ,

From the example you've provided as far as I understand you need to achieve this:

ERD_0-1632994359207.png

Measures:

MATvalue = 
VAR currentYear = MAX ( 'Date'[Year] )
VAR latestDay = DAY ( MAXX ( ALL ( T6[Date] ), T6[Date] ) )
VAR latestMonth = MONTH ( MAXX ( ALL ( T6[Date] ), T6[Date] ) )
VAR MATDate = DATE ( currentYear, latestMonth, latestDay )
VAR firstDay = EDATE ( MATDate + 1, -12 )
RETURN
    CALCULATE (
        SUM ( T6[No. of Services] ),
        'Date'[Date] >= firstDay,
        'Date'[Date] <= MATDate
    )

To have correct totals:

MATresult = 
IF (
    HASONEVALUE ( 'Date'[Year] ),
    [MATvalue],
    SUMX ( VALUES ( 'Date'[Year] ), [MATvalue] )
)

MAT%:

MAT% = 
VAR currentValue = [MATvalue]
VAR previousValue = CALCULATE ( [MATvalue], DATEADD ( 'Date'[Date], -1, YEAR ) )
RETURN
    IF (
        HASONEVALUE ( 'Date'[Year] ),
        DIVIDE ( currentValue - previousValue, previousValue ),
        BLANK ()
    )

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

7 REPLIES 7
ERD
Super User
Super User

Hi @enghone09 ,

From the example you've provided as far as I understand you need to achieve this:

ERD_0-1632994359207.png

Measures:

MATvalue = 
VAR currentYear = MAX ( 'Date'[Year] )
VAR latestDay = DAY ( MAXX ( ALL ( T6[Date] ), T6[Date] ) )
VAR latestMonth = MONTH ( MAXX ( ALL ( T6[Date] ), T6[Date] ) )
VAR MATDate = DATE ( currentYear, latestMonth, latestDay )
VAR firstDay = EDATE ( MATDate + 1, -12 )
RETURN
    CALCULATE (
        SUM ( T6[No. of Services] ),
        'Date'[Date] >= firstDay,
        'Date'[Date] <= MATDate
    )

To have correct totals:

MATresult = 
IF (
    HASONEVALUE ( 'Date'[Year] ),
    [MATvalue],
    SUMX ( VALUES ( 'Date'[Year] ), [MATvalue] )
)

MAT%:

MAT% = 
VAR currentValue = [MATvalue]
VAR previousValue = CALCULATE ( [MATvalue], DATEADD ( 'Date'[Date], -1, YEAR ) )
RETURN
    IF (
        HASONEVALUE ( 'Date'[Year] ),
        DIVIDE ( currentValue - previousValue, previousValue ),
        BLANK ()
    )

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

enghone09
Frequent Visitor

Hi @ERD 

 

Did you use a separate calendar table? I am getting a different result for MAT results. Please see below. 

 

Do you mind sharing your PBIX file?

 

enghone09_0-1633001534225.png

 

 

 

 

 

@enghone09 , cannot share files, but as for the Date table, yes, I use a separate one. This table is connected to your data table (Date column). You can easily create a Date table in Power Query or DAX.

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

enghone09
Frequent Visitor

@ERD  Thank you so much. It is all working now after adding a date table. 

 

May I ask why we need a date table? Is it not possible to achieve without a date table?

 

I am still learning on this. 

@enghone09 ,

Having a separate Date table is considered to be one of best practices. Moreover, Date table is mandatory for many Time intelligence functions that you might need in future.

You can read this article: https://kteam.ch/why-almost-every-power-bi-report-needs-a-date-table/ 

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

amitchandak
Super User
Super User

@enghone09 , Not very clear, but something like with YTD

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"7/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"7/31"))

Last 2 Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"7/31"))

3rd Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"7/31"))

 


Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

Hi @amitchandak ,

Thank you for your response. I have attached my sample data. 

Excel DATA 

 

- How can I change the above dax formula to be dynamic without having to change the date from "7/31" to "8/31" once the data become available?

- Is there a DAX formula that can calculate all 3 years in one measure? 

 

 


enghone09_0-1632981419156.png

 

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.