I have these two tables:
A data table...
ImaginaryData =
DATATABLE (
"Fruit", STRING,
"Colour", STRING,
"Amount", INTEGER,
{
{ "Apple", "Red", 10 },
{ "Apple", "Green", 5 },
{ "Pear", "Pink", 100 },
{ "Pear", "Blue", 65 },
{ "Orange", "Black", 12 },
{ "Orange", "White", 8 }
} )
A lookup table...
ImaginaryLookup =
DATATABLE (
"Fruit", STRING,
{
{ "Apple" },
{ "Pear" },
{ "Orange" }
} )
Then I created this simple 1-to-many relationship:
Now I am trying to create a Percent of Total measure to add to a table - but I want the percent of total to be based on the total of the fruits that are selected in a slicer of ImaginaryLookup:
This is what I have tried:
%Total =
DIVIDE(
sum( ImaginaryData[Amount] ),
CALCULATE(
sum( ImaginaryData[Amount] ),
ALL(ImaginaryData)
)
)
If all fruits are selected in the slicer then it works fine as I'd expect:
But if I select say "Orange" then the results are not what I want, as I'd like the 12 and the 8 to be a percentage of 20:
This also does not give me what I want:
%Total =
DIVIDE(
sum( ImaginaryData[Amount] ),
CALCULATE(
sum( ImaginaryData[Amount] ),
ALLEXCEPT(ImaginaryData, ImaginaryData[Fruit])
)
)
Because now if I select say Pears and Oranges then it is giving me the percent as a percent of each fruits total, rather than the percent of 185:
note to Alexis
If I try this:
%Total =
DIVIDE(
sum( ImaginaryData[Amount] ),
CALCULATE(
sum( ImaginaryData[Amount] ),
ALLSELECTED( ImaginaryData[Fruit])
)
)
I get this:
See Question&Answers more detail:
os