Forum Discussion
Difference between two columns or rows
- 9 years ago
Create a measure called "Difference"
Difference = IF ( HASONEVALUE ( 'Table'[YEAR] ), BLANK (), CALCULATE ( SUM ( 'Table'[AMOUNT] ), FILTER ( 'Table', 'Table'[YEAR] = MAX ( 'Table'[YEAR] ) ) ) - CALCULATE ( SUM ( 'Table'[AMOUNT] ), FILTER ( 'Table', 'Table'[YEAR] = MIN ( 'Table'[YEAR] ) ) ) )Then a measure called "%Inc"
%Inc = DIVIDE ( [Difference], CALCULATE ( SUM ( 'Table'[AMOUNT] ), FILTER ( 'Table', 'Table'[YEAR] = MIN ( 'Table'[YEAR] ) ) ) )Then just shrink the columns in your matrix that have no data so they don't show up, and make sure to turn the row totals on:
Oh and change the formatting/style for the measures as desired.
Perhaps something along the lines of:
Measure = CALCULATE(SUM([Column1]),FILTER(Table,[Year]=MAX([Year])) - CALCULATE(SUM([Column1]),FILTER(Table,[Year]=MIN([Year]))
Specifics will depend on your data. Can you post some raw, sample data?
- Raul9 years agoPost Patron
Hi smoupre,
This is the sample data:
ID ZONE DATEPHYS AMOUNT YEAR 1 EAST 01/02/2015 3.000 2015 2 WEST 01/02/2015 1.000 2015 3 NORTH 01/02/2015 2.500 2015 4 EAST 01/03/2015 1.320 2015 5 WEST 01/03/2015 2.200 2015 6 NORTH 01/03/2015 2.500 2015 7 EAST 01/02/2016 2.000 2016 8 WEST 01/02/2016 1.000 2016 9 NORTH 01/02/2016 2.000 2016 10 EAST 01/03/2016 3.200 2016 11 WEST 01/03/2016 1.000 2016 12 NORTH 01/03/2016 5.500 2016 I create the new measure like this:
Difference = CALCULATE(SUM([AMOUNT]);FILTER(Tabla1;[Year]=MAX([Year])) - CALCULATE(SUM([AMOUNT]);FILTER(Tabla1;[Year]=MIN([Year]))))
But it throw an error in the FILTER function. What is wrong?
Thanks
- dkay84_PowerBI9 years agoMicrosoft Employee
Create a measure called "Difference"
Difference = IF ( HASONEVALUE ( 'Table'[YEAR] ), BLANK (), CALCULATE ( SUM ( 'Table'[AMOUNT] ), FILTER ( 'Table', 'Table'[YEAR] = MAX ( 'Table'[YEAR] ) ) ) - CALCULATE ( SUM ( 'Table'[AMOUNT] ), FILTER ( 'Table', 'Table'[YEAR] = MIN ( 'Table'[YEAR] ) ) ) )Then a measure called "%Inc"
%Inc = DIVIDE ( [Difference], CALCULATE ( SUM ( 'Table'[AMOUNT] ), FILTER ( 'Table', 'Table'[YEAR] = MIN ( 'Table'[YEAR] ) ) ) )Then just shrink the columns in your matrix that have no data so they don't show up, and make sure to turn the row totals on:
Oh and change the formatting/style for the measures as desired.
- Raul9 years agoPost Patron
Perfect, this is the answer: I have to shrink the columns in mymatrix that have no data.
But the first visualization is not posible to do the same. Any suggestion?
- Greg_Deckler9 years agoCommunity Champion
Try this:
Difference = var MaxYear = MAX(Zones[YEAR]) var MinYear = MIN(Zones[YEAR]) RETURN CALCULATE(SUM([AMOUNT]),Zones[YEAR]=MaxYear) - CALCULATE(SUM([AMOUNT]),Zones[YEAR]=MinYear)
- Raul9 years agoPost Patron
I have corrected the measure and solved the error but the visual result is not as expected. Any ideas?
- dkay84_PowerBI9 years agoMicrosoft Employee
You need to put Zone in the rows, Year in the column, and Amount, Difference and %Inc as values.