Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
mayankkverma95
Regular Visitor

MAT Calculation in Power BI

Hi Everyone,

I got stuck while calculating MAT (Moving Annual Total) in my report.

Data Scenario- I have data which is only for latest period. Below is a raw snap:

ProductIDDateCurrent ValuesPrevious ValuesPrevious to Previous Values
PP1Jan-211005060
PP2Jan-212004070
PP3Feb-2130070300
PP4Feb-21250900400
PP5Mar-2135040200

 

First Column is my Product ID which is sold out, second column is my current year date, third column represent selling amount in the respective current year date. Fourth column is previous year selling amount for previous year date. For example in Row1, against Jan 2021, $ 200 selling recorded and $ 50 selling recorded in Jan 2020 and $ 60 recorded in 2019.

Now, I want to calculate MAT (for last 12 months, basis current selection of month).
I have created a Calendar table also in Power BI. But seems it is not working somehow.
Can you please provide the solution to this specific problem of calculating MAT given above my data structure.
Thank you!!
@Jimmy801 

1 ACCEPTED SOLUTION

Hi @mayankkverma95 ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Make a data conversion so that the values of different years are displayed in the same column and the corresponding dates are added respectively as shown in below screenshot

yingyinr_0-1618469972249.png

2. Create a measure as below to get MAT just as suggested by @amitchandak 

 

MTD = 
CALCULATE (
    SUM ( 'Table'[Values] ),
    DATESYTD ( DATEADD ( 'Date'[Date], -1, YEAR ), "12/31" )
)

 

In addition, please review the content in the following video. Help it can help you~

Power BI M Code for Moving Annual Total (MAT)

Best Regards

Community Support Team _ Rena
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

3 REPLIES 3
amitchandak
Super User
Super User

@mayankkverma95 , Not vey clear with help from date table

 

example

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

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

 

Rolling 12 = CALCULATE(Average(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

 

Rolling 12 = divide( CALCULATE(sum(Sales[Sales]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date]),-12,MONTH)) ,
CALCULATE(distinctCOUNT('Date'[Month Year]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-12,MONTH), filter(Sales,not(isblank(sum(Sales[Sales]))))))

 

 

Hi,
This solution will work only if i have all dates in Fact table (Including current and previous years). I have Only current year date in Fact Table. But for previous year values, I have those in third and fourth columns.

Hi @mayankkverma95 ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Make a data conversion so that the values of different years are displayed in the same column and the corresponding dates are added respectively as shown in below screenshot

yingyinr_0-1618469972249.png

2. Create a measure as below to get MAT just as suggested by @amitchandak 

 

MTD = 
CALCULATE (
    SUM ( 'Table'[Values] ),
    DATESYTD ( DATEADD ( 'Date'[Date], -1, YEAR ), "12/31" )
)

 

In addition, please review the content in the following video. Help it can help you~

Power BI M Code for Moving Annual Total (MAT)

Best Regards

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.