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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
gino_becerra
Regular Visitor

Create a measure that calculates the difference between two columns on a matrix with filter visuals

I have seen similar needs but I havent been able to find the correct solution. 

I have a ONE data table that lists all the hours by equipment type by date. so i created a matrix that displays the hours in one year and the next (in this case 2024 and 2025). i need a measure that will calculate the difference between the two columns when the data on the columns is dynamic based on a three filter visuals.

can anyone guide me on the solution please. 

 

gino_becerra_0-1739291636019.pnggino_becerra_1-1739291677243.png

 

 

4 REPLIES 4
sjoerdvn
Super User
Super User

You can also try visual calculations. Note that I added an IF tto supress the values of a diff column for the first year, but it will still show an empty column.

sjoerdvn_0-1739874528006.png

 

Anonymous
Not applicable

Hi @gino_becerra 

 

Thanks for the reply from Greg_Deckler .

 

Do you want to modify the column subtotal to be the difference between the largest year in the table and the previous year?

 

My sample:

vxuxinyimsft_2-1739785726723.png

 

If so, you could try this:

Diff = 
VAR _year = MAXX(ALL('Table'), 'Table'[Date].[Year])
VAR _max = CALCULATE(SUM('Table'[Hours]), YEAR('Table'[Date]) = _year)
VAR _min = CALCULATE(SUM('Table'[Hours]), YEAR('Table'[Date]) = _year - 1)
RETURN
IF(
    ISFILTERED('Table'[Date].[Year]),
    SUM('Table'[Hours]),
    _max - _min
)

 

Put the measure into Values

vxuxinyimsft_1-1739785210048.png

 

Output:

vxuxinyimsft_0-1739785126928.png

 

Best Regards,
Yulia Xu

 

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

Thanks for the tip but something is not right. The code for my measure is below. now i think i ommited something. I have a table with the hours and equipment types (Table1) but the dates are coming from a related calendar table (table3). 

 

also when i add the measure to values it creates another data column....

gino_becerra_1-1739911956016.png

 

gino_becerra_2-1739911972984.pnggino_becerra_3-1739912003872.png

 

 

 

Greg_Deckler
Community Champion
Community Champion

@gino_becerra Maybe:

Measure = 
  VAR __Category = MAX( 'Table1'[Category] )
  VAR __YearMin = YEAR( MIN( 'Table1'[DT Reading] )
  VAR __YearMax = YEAR( MAX( 'Table1'[DT Reading] )
  VAR __Table1 = 
    FILTER( 
        ALLSELECTED( 'Table1' ), [Category] = __Category && YEAR( [DT Reading] ) = __YearMin
    )
  VAR __Table2 = 
    FILTER( 
        ALLSELECTED( 'Table1' ), [Category] = __Category && YEAR( [DT Reading] ) = __YearMax
    )
  VAR __Result = SUMX( __Table2, [Hours] ) - SUMX( __Table1, [Hours] )
RETURN
  __Result


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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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