Search code examples
sumpowerbidaxmeasure

PowerBI Veil totals if there is unveiled cell values that do not meet threshold


OK my primary issue is to protect the privacy of those the table are tracking, we want to veil values that don't meet a threshold.
So if a value is below 5 show a veil_text like "*".

Easy enough so:
Val = Count(Orders[EmployeeID]) Val_Veiled = if([Val] < 5, "*", [Val])

Val and Val Veiled are both measures.

State | Val     | Val_Veiled
NJ    | 10      | 10  
NY    | 15      | 15  
PA    | 3       | *  
VA    | 1       | *  
AK    | (blank) | *  
Total | 29      | 29  

Which even works fine for:

State | Val | Val_Veiled
PA    | 3   | *  
VA    | 1   | *  
Total | 4   | *  

Problem comes in for:

State | Val | Val_Veiled
NY    | 15  | 15  
PA    | 3   | *  
Total | 18  | 18  

For the last case scenario I would want to veil the total because otherwise you can easily determine what PA's value is.

Similarly we want to make sure it works correctly for:

State | Val | Val_Veiled
NY    | 15      | 15  
AK    | (blank) | *  
PA    | 3       | *  
Total | 18      | 18  

Idealistically I don't want the solution to this to be tied to state, I want it just to be tied only to [Val] but I don't know if that is feasible. So if there is a different column that the [Val] measure gets broken across, I want it to still retain the veil logic. IE If I break it across region, or by store, or by product, all feasible, and works for the values perfectly, but not the totals.

If the only way is to tie the logic to the break out column, I could deal with it for now. But I am not sure how to break out of the scope of the total, to check the selected values totals for comparison to determine if the Total also needs to be veiled.


Solution

  • If I understand your requirement correct, this following measure should serve your purpose. Overall the logic is what you are looking for. But you can adjust the combination in last RETURN step if you do not get expected output-

    mask_val = 
    
    VAR total_val = SUM(your_table_name[val])
    
    VAR total_row = COUNTROWS(your_table_name)
    
    VAR count_blank_row = 
    CALCULATE(
        COUNTROWS(your_table_name),
        FILTER(
            your_table_name,
            your_table_name[val] = BLANK()
        )
    )
    
    VAR count_less_val = 
    CALCULATE(
        COUNTROWS(your_table_name),
        FILTER(
            your_table_name,
            your_table_name[val] < 5 
                && your_table_name[val] >= 1
        )
    )
    
    RETURN IF(
        count_less_val = 1 
            || (count_less_val = 0 && count_blank_row >= 1)
            || total_row = count_less_val,
        "*",
        total_val
    )
    

    Here is sample output for different cases you explain-

    enter image description here