I am trying to do a custom sort on my data. The data is in long format. I have created one measure that I have applied to the matrix by item. What I want to do now is do a custom sort on the items for which I created a custom sort table and connected it to the main table. Everything seems to be working fine as long as I am using the item field from the main table i.e. "Data for Table 6" but as soon as I put the item field from the custom sort i.e. "table1" into the matrix I have created to custom sort it, my measure values change to 100%.
Below is a link to the data with the measure and model that I have created
https://1drv.ms/u/c/7f8955a5543984a5/ERrE3c6wXtxIoUAqoizOzeUBjOwnXjrktQOZr-R_7O6sBA?e=cSEEOL
Thank you
You can use ALLEXCEPT
function instead of multiple ALL
. Together with using variables and SWITCH
, you can have the following more maintainable and easier to read measure.
yourMeasure =
var volS =
DIVIDE(
CALCULATE(SUM('Data Table Page 6'[Sales Value (000)] ), 'Data Table Page 6'[Attribute] = "Value Share"),
CALCULATE(SUM('Data Table Page 6'[Sales Value (000)] ), 'Data Table Page 6'[Attribute] = "Value Share", ALLEXCEPT('Data Table Page 6', 'Data Table Page 6'[Periods]))
)
var valS =
DIVIDE(
CALCULATE(SUM('Data Table Page 6'[Sales Value (000)] ), 'Data Table Page 6'[Attribute] = "Volume Share"),
CALCULATE(SUM('Data Table Page 6'[Sales Value (000)] ), 'Data Table Page 6'[Attribute] = "Volume Share", ALLEXCEPT('Data Table Page 6', 'Data Table Page 6'[Periods]))
)
var avgP =
DIVIDE(
SUM('Data Table Page 6'[Sales Value (000)]) ,
SUM('Data Table Page 6'[Sales (KGS) (000)])
)
var wd = AVERAGE ( 'Data Table Page 6'[Weighted Distribution - Reach] )
return
SWITCH( SELECTEDVALUE ( 'Data Table Page 6'[Attribute] ),
"Value Share", volS,
"Volume Share", valS,
"Average price", FORMAT(avgP, "Standard"),
"WD", FORMAT(wd, "Standard")
)
DAX works backwards meaning it will only calculate the needed variables.