Forum Discussion
Year Difference calculation after performing PIVOT
I am sure this has been asked but after all my work, I could not find solution for it. I have Excel Data into Power BI desktop file like this (I mentioned only main related columns, otherwise there are lot of other columns too)
Manufacturer ModelName Year Instances .......ColumnN
M1 AA 2014 5 ..............
M1 AA 2015 10 ..............
M1 AA 2014 3 ..............
M1 AA 2016 20 ..............
M1 AA 2015 4 ...............
and so on...............
So I want to get Instances differences between 2014 & 2015 as well as 2016 & 2015 for each Model Name. Logically I should perform PIVOTING first and get In-memory table like this
ModelName 2014 Instance 2015 Instance 2016 Instance
AA 8 14 20
...... .......... ............ .............
However I am not able to get this (in-memory) PIVOT table after all my research. Any help please?
NOTE: I don't want to display this PIVOT table using Matrix visual, instead as mentioned above I want to get Difference of each Year and then display using Column Chart. For example, Model AA difference between 2015 & 2014 is 6 whereas between 2016 & 2015 is 6.
Thanks
2 Replies
- Zubair_Muhammad
Community Champion
Hi malikirfan28
See if this Measure helps you
DifferenceFromPriorYear = VAR LastyearTotal = CALCULATE ( SUM ( TableName[Instances] ), FILTER ( ALLEXCEPT ( TableName, TableName[Model Name], TableName[Manufacturer] ), TableName[Year] = SELECTEDVALUE ( TableName[Year] ) - 1 ) ) RETURN SUM ( TableName[Instances] ) - LastyearTotal- malikirfan28
Helper II
Dear Zubair_Muhammad,
I am sorry if I could not explain my question properly. This measure is summing up all year instances BUT I need to calculate difference of each year like 2016-2015 Instances and 2015-2014 instances. You can use following excel data source for verification. I have included "required" sheet what I needed to have.
The given measure formula creates output something like this
For given data source (pasted image here as well)
The resultant charts should be like these: