Forum Discussion

IMK's avatar
IMK
Helper I
9 years ago
Solved

Need help with null cells

I am calculating NPS with Power BI and created a new column for this. I have Grades column that holds grades given by customer and I ma creating new column which looks at the grade in Grade column an...
  • Sean's avatar
    9 years ago

    IMK

    This is happening because the empty values are treated as zeros and falling into the first condition

    There's couple ways you can handle this depending on whether 0 is actually a legitimate value or not.

    (meaning could you really have a zero as a grade)

    So if zero can't be really a value all you have to change is the comparison from >= 0 to just > 0

    Column 2 =
    SWITCH (
        TRUE ();
        'Table1'[Grades] > 0
            && 'Table1'[Grades] <= 6; "Detractors";
        'Table1'[Grades] = 7
            || 'Table1'[Grades] = 8; "Passives";
        'Table1'[Grades] = 9
            || 'Table1'[Grades] = 10; "Promoters";
        "Empty"
    )

    Now if zero can in fact be a grade use this instead which first checks if the value is blank

    Column 3 =
    IF (
        ISBLANK ( 'Table1'[Grades] );
        "Empty";
        SWITCH (
            TRUE ();
            'Table1'[Grades] >= 0
                && 'Table1'[Grades] <= 6; "Detractors";
            'Table1'[Grades] = 7
                || 'Table1'[Grades] = 8; "Passives";
            'Table1'[Grades] = 9
                || 'Table1'[Grades] = 10; "Promoters"
        )
    )

    Hope this helps! :smileyhappy:

  • Sean's avatar
    Sean
    9 years ago

    When you say SUM I suspect you mean COUNT each category and the overall total excluding the "empty" values

    So to calculate each category individually...

    Detractors =
    CALCULATE (
        COUNTA ( Table1[Column 3] );
        FILTER ( 'Table1'; 'Table1'[Column 3] = "Detractors" )
    )
    
    Passives =
    CALCULATE (
        COUNTA ( Table1[Column 3] );
        FILTER ( 'Table1'; 'Table1'[Column 3] = "Passives" )
    )
    
    Promoters =
    CALCULATE (
        COUNTA ( Table1[Column 3] );
        FILTER ( 'Table1'; 'Table1'[Column 3] = "Promoters" )
    )

    Then to calculate the overall total - couple ways depending on which column you decide to FILTER

    Total (NonBlank) =
    CALCULATE (
        COUNTA ( Table1[Grades] );
        FILTER ( Table1; Table1[Grades] <> BLANK () || Table1[Grades] = 0 )
    )
    
    Total (NonBlank) 2 =
    CALCULATE (
        COUNTA ( Table1[Grades] );
        FILTER ( Table1; Table1[Column 3] <> "Empty" )
    )

    If you FILTER the [Grades] column as in the first formula you have to exclude blanks but include zeros

    If you FILTER [Column 3] instead all you have to exclude is "Empty" since we already took care of this in the [Column 3] formula

    Hope this helps! :smileyhappy: