Forum Discussion

Aklys's avatar
Aklys
Helper I
2 years ago
Solved

Calculation Groups, Relationships and Filters

I'm looking for an explanation for why this occurs and maybe a solution if there is one.   Setup: I have two tables that are related to each other and a calculation group/item. I use one table as ...
  • OwenAuger's avatar
    2 years ago

    Thanks for that Aklys - that PBIX clarified the issue 🙂

     

    The immediate issue is that the calculation items are converting blank values into nonblank values in some cases.

     

    Here is one way to rewrite two the calculation items to avoid this issue:

     

     

    -------------------------------------------------
    -- Calculation Item "KPIs__Direct_and_Simplified"
    -------------------------------------------------
    VAR KPIDisplay = [KPI_Display]
    RETURN
        IF (
            NOT ISBLANK ( KPIDisplay ),
            SWITCH (
                KPIDisplay,
                9000, "High Risk",
                9001, "At Risk",
                9002, "On Track",
                "Unknown"
            )
        )
    
    -------------------------------------------------
    -- CALCULATIONITEM "KPIs__Display"
    ------------------------------------------------- 
    IF (
        CONTAINSSTRING ( SELECTEDMEASURENAME ( ), "*KPI*Display*" ),
        VAR MeasureValue = SELECTEDMEASURE ( )
        RETURN
            IF (
                NOT ISBLANK ( MeasureValue ),
                SWITCH (
                    MeasureValue,
                    9000, "High Risk",
                    9001, "At Risk",
                    9002, "On Track",
                    "Unknown"
                )
            ),
        SELECTEDMEASURE ( )
    )

     

     

     

    The reason you were seeing different behaviour when filtering on Item Type vs Item Type Lookup is more complicated, and relates to auto-exist, compounded by the main issue of converting blanks to nonblanks.

     

    In this example, when the Item Type column on the slicer is from a different table from the other columns used in the visual, non-existent combinations of those columns are not automatically eliminated in the DAX query generated by the visual, so the nonblank measure values (that were originally blank) appear in the visual.

     

    In summary, I would recommend adding checks to ensure that blank values returned by an underlying measure are not converted to nonblank values (within calculation items or otherwise) unless there is a specific reason to do so. 

    (Also follow the recommendations in the auto-exist article where possible.)

     

    Regards