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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
EuanKonnektis
Frequent Visitor

Difference Measure between filtered column values in a matrix

Hi,

 

There could be a suggestion for this elsewhere, but I've been searching for a while and not found anything! I pull an export from a system every week, the spreadsheet is named the date of the export and it's saved in a folder. Power BI uses that folder as the data source and the source name is converted into a date within the query.

 

Each row in the export has a unique ID and a value alongside it. I have created a matrix which looks similar to the below:

Export Date       31st July 2019      31st August 2019   30th September 2019    31st October 2019
Unique ID m      MB Usage            MB Usage               MB Usage                      MB Usage
123456              205                       303                         210                                 300 

112233              201                       200                         210                                 211

232123              101                       100                         500                                 400

534234              650                       300                         250                                 241

 

I'm wanting to create a measure that will fit in between each column and work out the difference between one date's value and the other.

 

There is actually more data than these included dates because a sheet is exported every week, but I have the visual only look at the last date of each month.

 

Many thanks in advance.

5 REPLIES 5
Greg_Deckler
Super User
Super User

So, I would expect that would be something along the lines of:

 

Measure 1 = CALCULATE([Measure],PREVIOUSMONTH('Dates'[Date]))

 

Or you could brute force it similar to:

 

Measure 1 =
  VAR __Date = MAX('Table'[Date])
  VAR __Year = YEAR(__Date)
  VAR __Month = MONTH(__Date)
  VAR __Day = DAY(__Date)
  VAR __PreviousDate = 
    IF(__Month = 1,DATE(__Year - 1,12,__Day),DATE(__Year,__Month-1,__DAy))
RETURN
  CALCULATE([Measure],'Table'[Date] = __PreviousDate)

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

 

Thanks for your quick response. Have I understood you correctly by using this measure for the first example:

Measure = CALCULATE('Data Usage'[Total Usage],PREVIOUSMONTH('Data Usage'[Export Date].[Date]))
 
That one didn't display any values in the matrix:
 
screenshot.PNG

 

Hi , @EuanKonnektis 

There's nothing wrong with @Greg_Deckler  solution.

I suspect you didn't use the correct calendar table.
"Previousmonth" is a time intelligence function that needs to be used with the calendar table of consecutive date columns.

 

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

I do still seem to be having issues with this and "Difference" is currently returning a blank field.

 

I have another table called 'App Usage' which has a date row that runs every day of the month (between 02-06-2019 to today).

 

I have set up a relationship between 'Data Usage'[Export Date] and 'App Usage'[Date].

 

Is there still something I'm missing? Apologies, I'm still getting used to this!

 

Here is how it looks now:

 

Screenshot.PNG

Hi @v-easonf-msft - ahhh, fantastic, I see! My export date only has a date every week.

 

So do I need to have a consecutive date calendar date table that has a relationship with the export date column?

 

Many thanks,

 

Euan.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.