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

Summarizing the differences between months

Hello,
 
I am trying to summarize the differences between each month's values compared to the previous month in a matrix.
 
Right now, I have this measure, which results in the correct sums and totals in every case, EXCEPT when there is no value for a month. Then, the calculation SHOULD show the negative value from the previous month (difference = this month - previous month) but instead it shows nothing, and also the total for the row also goes wrong. 
 
 
The measure 
Diff =
IF(HASONEFILTER('Data'[Year/Month]),
CALCULATE(SUM('Data'[EUR])- CALCULATE(SUM('Data'[EUR]), PREVIOUSMONTH('Data'[Year/Month]))),
CALCULATE(SUM('Data'[EUR]), FILTER('Data', 'Data'[Year/Month] = MAX('Data'[Year/Month]))) -CALCULATE(SUM('Data'[EUR]), PREVIOUSMONTH('Data'[Year/Month])))
 
Attached are pictures from the matrix in Power BI, and a table from excel which shows how the values should be. 
How the line looks in the MatrixHow the line looks in the MatrixHow the line should look like (Calculated manually in excel)How the line should look like (Calculated manually in excel)
 
How should the measure be modified in order to achieve this?
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello

 

The issue was fixed with the following syntax:

 

Diff =
VAR Diff =
CALCULATE(SUMX('Data','Data'[EUR]) -CALCULATE(SUMX('Data','Data'[EUR]), PREVIOUSMONTH('Date Table'[Date])))
VAR Total =
CALCULATE(SUMX('Data','Data'[EUR]), FILTER('Data', 'Data'[Year/Month] = MAXX(ALL('Data'),'Data'[Year/Month]))) -CALCULATE(SUMX('Data','Data'[EUR]), PREVIOUSMONTH('Date Table'[Date]))

RETURN
IF(HASONEFILTER('Date Table'[Year-month]),Diff,Total)

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hello

 

The issue was fixed with the following syntax:

 

Diff =
VAR Diff =
CALCULATE(SUMX('Data','Data'[EUR]) -CALCULATE(SUMX('Data','Data'[EUR]), PREVIOUSMONTH('Date Table'[Date])))
VAR Total =
CALCULATE(SUMX('Data','Data'[EUR]), FILTER('Data', 'Data'[Year/Month] = MAXX(ALL('Data'),'Data'[Year/Month]))) -CALCULATE(SUMX('Data','Data'[EUR]), PREVIOUSMONTH('Date Table'[Date]))

RETURN
IF(HASONEFILTER('Date Table'[Year-month]),Diff,Total)

Ashish_Mathur
Super User
Super User

Hi,

Share the download link of your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, I need more information.

Is the value showed in your snapshot 'Data'[EUR] or measure Diff, if it's measure Diff, please show the corresponding 'Data'[EUR].

In your first snapshot, you covered the value of 2022-3, 2022-4 and 2022-5, are they blank or zero?

 

Waiting for your reply.

Best Regards,
Community Support Team _ kalyj

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.

Top Solution Authors