Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Using CROSSFILTER to work around Single Direction Relationship

Data Model WarehouseLocation - Table of locations within a warehouse WarehousePackage - Table of warehouse pick locations by package Single Direction relationship from WarehouseLocation to Warehou...
  • daxer-almighty's avatar
    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"
            )
            
        )