0
votes

Here is the source data:

https://i.stack.imgur.com/raYom.png

Columns: [Version, Unit, Customer, Quarter, Sales)

Here are the potential values:

https://i.stack.imgur.com/REmnV.png

*Note: We may have 10 different versions and 20+ different quarter year combinations.

Here is the output matrix in Power BI:

https://i.stack.imgur.com/FA1UE.png

*Users can select a Version and two quarters to compare.

Here are the Power BI Visualizations and Fields:

https://i.stack.imgur.com/VWd5A.png

I would like to create a measure to calculate the difference between Version 1 and 2 like this (Columns E and H):

https://i.stack.imgur.com/yWRQx.png

I'm able to create a new table with columns of sales for Version 1,2,3 then calculate the difference. The problem is I need the version and quarter to be dynamic. Any ideas how to do this in Power BI?

2

2 Answers

1
votes

You can do something like

    Delta = IF (HASONEVALUE('Table'[Version]),
                   SUM('Table'[Sales]), 
                    CALCULATE(sum('Table'[Sales]), LASTNONBLANK('Table'[Version], sum('Table'[Sales]))) 
                  - CALCULATE(sum('Table'[Sales]), FIRSTNONBLANK('Table'[Version], sum('Table'[Sales])))
)

So whenever you have two versions in the filter context, it subtracts the first from the last, and whenever only one version is in the filter context, it passes the value through.

0
votes

To add to this.

How to fix the duplicated columns in each of the subcategories.

I used the below DAX but somehow it's duplicated the calculated column "Delta TMCGP%" in all the subcategories. when i just want to show it at the end of the matrix table (Power BI)

Delta TMCGP% = CALCULATE([TMCGP%], FILTER( ALL(BC_Dashboard_V4_Standard[TYPE (groups)]), BC_Dashboard_V4_Standard[TYPE (groups)]="4_CWV") ) - CALCULATE([TMCGP%], FILTER( ALL(BC_Dashboard_V4_Standard[TYPE (groups)]), BC_Dashboard_V4_Standard[TYPE (groups)]="5_POR" ) )

enter image description here