Forum Discussion
Using CROSSFILTER to work around Single Direction Relationship
- 5 years ago
Anonymous
I don't have time to optimize this measure... but you might not even need it. To use the measure correctly (and understand its behaviour) you have to have a correct dimensional model and follow Best Practices of dimensional modeling in PBI (for instance, you should never slice by attributes in the fact table apart from a degenerate dimension). It's up to you to create correct models and take precautions to guide users to use them correctly.
[First Isle Count] = var vAisleIsInScope = ISINSCOPE( WarehouseLocation[Aisle] ) var vCurrentAisle = SELECTEDVALUE( WarehouseLocation[Aisle] ) var vMissingAisleNotInScope = vCurrentAisle <> "missing" RETURN IF( vAisleIsInScope && vMissingAisleNotInScope, // Need to find all the packages // in the current context that have // the selected isle as the first one. // This must happen after the removal // of all filters from WarehouseLocation // and exclusion of the missing isle. All // other filters ARE HONORED. CALCULATE( SUMX( DISTINCT( WarehousePackage[Package ID] ), 1 * CALCULATE( // Change MINX to MAXX to have the // other measure, Last Isle Count. vCurrentAisle = MINX( SUMMARIZE( WarehousePackage, WarehouseLocation[Aisle] ), WarehouseLocation[Aisle] ) ) ), REMOVEFILTERS( WarehouseLocation ), WarehouseLocation[Aisle] <> "missing" ) )
Anonymous
I don't have time to optimize this measure... but you might not even need it. To use the measure correctly (and understand its behaviour) you have to have a correct dimensional model and follow Best Practices of dimensional modeling in PBI (for instance, you should never slice by attributes in the fact table apart from a degenerate dimension). It's up to you to create correct models and take precautions to guide users to use them correctly.
[First Isle Count] =
var vAisleIsInScope = ISINSCOPE( WarehouseLocation[Aisle] )
var vCurrentAisle = SELECTEDVALUE( WarehouseLocation[Aisle] )
var vMissingAisleNotInScope = vCurrentAisle <> "missing"
RETURN
IF( vAisleIsInScope && vMissingAisleNotInScope,
// Need to find all the packages
// in the current context that have
// the selected isle as the first one.
// This must happen after the removal
// of all filters from WarehouseLocation
// and exclusion of the missing isle. All
// other filters ARE HONORED.
CALCULATE(
SUMX(
DISTINCT( WarehousePackage[Package ID] ),
1 * CALCULATE(
// Change MINX to MAXX to have the
// other measure, Last Isle Count.
vCurrentAisle = MINX(
SUMMARIZE(
WarehousePackage,
WarehouseLocation[Aisle]
),
WarehouseLocation[Aisle]
)
)
),
REMOVEFILTERS( WarehouseLocation ),
WarehouseLocation[Aisle] <> "missing"
)
)
Thank you for the detailed reply! Completely agree that this model does not follow best practices for this use case; it was developed for a more general self-service option for less technical end users.