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
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

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
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.