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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
sahildoshi
Helper I
Helper I

Power BI Matrix to show Total and Difference

Hi All, I am working on a requirement where I need to show Month on Month sales in a matrix. Below is my input data.

 

Input_MOM.png

 

User need to select the Financial Year and all the Months who fall under that year should get displayed based on data availability.

The catch is, along with MoM Sales, Total sales and Difference between latest and latest-1 month sales should get displayed.

Output_MOM.png

 

I have put Month field is put under column section of matrix and column total is enabled. But how do I get the Difference between latest month and latest-1 sales dynamically. 

 

Please help me achieve it. @GilbertQ @amitchandak 

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @sahildoshi ,

 

Please follow the steps:

1. Assume your Month column is Text type, I add a new Date column:

Eyelyn9_0-1657256878885.png

2. Then create a measure:

Measure = 
var _max=CALCULATE( LASTDATE('Table'[Date]),ALLEXCEPT('Table','Table'[Region]))
var _pre= EDATE(_max,-1)
var _diff=CALCULATE(SUM('Table'[Amount]),FILTER('Table',[Date]=_max)) - CALCULATE(SUM('Table'[Amount]), FILTER('Table',[Date]=_pre))
return IF(ISINSCOPE('Table'[Date].[Year]),SUM('Table'[Amount]),_diff)

But since I used Date hierarchies, the header label could not be changed to Total and Diff seperately.

Here is the Output:

Eyelyn9_1-1657257079277.png

 

Best Regards,
Eyelyn Qin
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
v-eqin-msft
Community Support
Community Support

Hi @sahildoshi ,

 

Please follow the steps:

1. Assume your Month column is Text type, I add a new Date column:

Eyelyn9_0-1657256878885.png

2. Then create a measure:

Measure = 
var _max=CALCULATE( LASTDATE('Table'[Date]),ALLEXCEPT('Table','Table'[Region]))
var _pre= EDATE(_max,-1)
var _diff=CALCULATE(SUM('Table'[Amount]),FILTER('Table',[Date]=_max)) - CALCULATE(SUM('Table'[Amount]), FILTER('Table',[Date]=_pre))
return IF(ISINSCOPE('Table'[Date].[Year]),SUM('Table'[Amount]),_diff)

But since I used Date hierarchies, the header label could not be changed to Total and Diff seperately.

Here is the Output:

Eyelyn9_1-1657257079277.png

 

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

amitchandak
Super User
Super User

@sahildoshi , Use a separate month/ date table.

 

Create a date from the month

new column

date = datevalue("01-" & [Month])

 

then you can use time intelligence

measures

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

 

Or have month rank column on YYYYMM or month start date

 

Month Rank = RANKX(all('Date'),'Date'[Month Start date],,ASC,Dense)

 

then measure

 

This Month = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank])))
Last Month = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank])-1))

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

thanks for the quick reply @amitchandak , but when I have Jun-22 data also available, the output table should look like below.

Output_MOM_2.png

Dynamically every month sales should get added. Total of every month should get calculated and Diff column should display difference of latest 2 months.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.