In PowerBI what options are there to hide/redact/mask values in visuals to anonymise data - powerbi

What options are there in PowerBI to suppress, redact or hide values to anonymise values in reports and visuals without loosing detail and have that restriction apply to multiple pages in a report?
Cat
Count
%
Category 1
23
10
Category 2
2
0.9%
Category 3
4
1.7%
So that its possible to keep the rows but end up with a placeholder where count is <4 and % is greater than 1% but less than 2%
Cat
Count
%
Category 1
23
10
Category 2
*
0.9%
Category 3
4
*
So far my experience has been
a measure with a filter applied will hide rows but you can't apply a measure filter to an entire page or all report pages.
Ive seen mention of conditional formatting to hide the value by having the font and background the same colour but that seems open to error and labour intensive.
I also want to be clear when a value has been suppressed or masked
I suspect there is a more better way but I haven't been able to figure out where to even start.

OK, I have something working but you will need Tabular Editor to create a calculation group. Here are the steps.
I'm using the following table (named "Table") as the source data.
Add two measures (calculation groups only work on measures) as follows.
% Measure = SUM('Table'[%])
Count Measure = SUM('Table'[Count ])
Open tabular editor and create a new calculation group named "CG" with a calculation item named "Mask". Paste the following code into the calculation item.
if (
(selectedmeasurename() = "% Measure" && selectedmeasure() >1 && selectedmeasure() <2)
||
(selectedmeasurename() = "Count Measure" && selectedmeasure() <4)
,"*",selectedmeasure()
)
4. Save the calculation group and in Power BI drag the name column onto the filter for all pages as follows, ensuring it is selected:
The masking will now happen across all reports automatically. Below you can see the same table on two different reports which have now been successfully masked.

It depends on your data connection type as to whether this is available, but a calculated column (instead of a measure) can be used as a filter at the "this page" or "all pages" level.
If this option is available, then you can find it right next to the "New Measure" field.
Using this and your sample data above, I created a couple of calculated columns and show the resulting table. You can then display these columns and use them as filters throughout the report. Your DAX may be slightly different depending on how the actual data is formatted and such.
Count Calculated Column
Masked Count =
IF(
'Table'[Count] < 4,
"*",
CONVERT('Table'[Count], STRING)
)
% Calculated Column
Masked % =
IF(
'Table'[%] > .01 && 'Table'[%] < .02,
"*",
CONVERT('Table'[%] * 100, STRING) & "%"
)
Resulting Table
Example of how the filter can be used
The values of these columns will update as your data source is refreshed in Power BI. However, calculated columns aren't available for Live Connection, in which case you would have to do this kind of logic at a lower level (in Analysis Services for example).
Additionally, you could potentially use Power Query Editor to accomplish this kind of thing.

Related

Power Bi, Return percentage of grand total but the column's values are text

I am trying to return the percentage of the grand total from #number of clients using the second and fourth columns. The number of clients values are text and are collected using Count('Table'[Column]). That is where I have run into issues. When I try Countrows() or AllSelected() to try and work around it, it returns all the rows and doesn't keep the filters I have set.
My current measures:
Client Total = COUNTA('Table'[Client_Name])
% with at least 1 document = DIVIDE(SUM('Table'[At Least 1 Document Sum]), [Client Total])
Right now, it only calculates the percentage based on the filtered # of clients in the same row versus the grand total. I am hoping to have it use a dynamic grand total that is shown at the bottom of the table.
[Current Table] (https://i.stack.imgur.com/IG254.png)
Here is my solve
Measure Name = CALCULATE(COUNTROWS('Table'),ALLSELECTED('Table'))
Then:
Measure Name = SUM('Table'[At Least 1 Document Sum])/'Table'[Measure]

DAX selecting and displaying the max value of all selected records

Problem
I'm trying to calculate and display the maximum value of all selected rows alongside their actual values in a table in Power BI. When I try to do this with the measure MaxSelectedSales = MAXX(ALLSELECTED(FactSales), FactSales[Value]), the maximum value ends up being repeated, like this:
If I add additional dimensions to the output, even more rows appear.
What I want to see is just the selected rows in the fact table, without the blank values. (i.e., only four rows would be displayed for SaleId 1 through 4).
Does anyone know how I can achieve my goal with the data model shown below?
Details
I've configured the following model.
The DimMarket and DimSubMarket tables have two rows each, you can see their names above. The FactSales table looks like this:
SaleId
MarketId
SubMarketId
Value
IsCurrent
1
1
1
100
true
2
2
1
50
true
3
1
2
60
true
4
2
2
140
true
5
1
1
30
false
6
2
2
20
false
7
1
1
90
false
8
2
2
200
false
In the table output, I've filtered FactSales to only include rows where IsCurrent = true by setting a visual level filter.
Your max value (the measure) is a scalar value (a single value only). If you put a scalar value in a table with the other records, the value just get repeated. In general mixing scalar values and records (tables) does not really bring any benefit.
Measures like yours can be better displayed in a KPI or Multi KPI visual (normally with the year, that you get the max value per year).
If you just want to display the max value of selected rows (for example a filter in your table), use this measure:
Max Value = MAX(FactSales[Value])
This way all filter which are applied are considered in the measures calculation.
Here is a sample:
I've found a solution to my problem, but I'm slightly concerned with query performance. Although, on my current dataset, things seem to perform fairly well.
MaxSelectedSales =
MAXX(
FILTER(
SELECTCOLUMNS(
ALLSELECTED(FactSales),
"id", FactSales[SaleId],
"max", MAXX(ALLSELECTED(FactSales), FactSales[Value])
),
[id] = MAX(FactSales[SaleId])
),
[max]
)
If I understand this correctly, for every row in the output, this measure will calculate the maximum value across all selected FactSales rows, set it to a column named max and then filter the table so that only the current FactSales[SaleId] is selected. The performance hit comes from the fact that MAX needs to be executed for every row in the output and a full table scan would be done when that occurs.
Posted on behalf of the question asker

Toggle between different "Show Values As" options in Slicer

I am using a Matrix in PowerBI to show the Sales Manager and Sales Reps down the rows, and the different ship method and source of the order across the columns and a count of unique orders in the values.
Below shows the table structure I have, and I want to switch between "Show Values As": the original values I calculate with my measure (count of unique orders) and % of Row Total.
Currently, my only solution is to create a second table showing the different values, but I think that's a cheap solution. I've seen solutions with helper tables but since my values are a measure I cannot invoke them in other measures, and as the sources or ship methods are filtered I want the % of row total to reflect the filter as well so using a countx formula won't account for that (if I housed it in a formula).
I'm still somewhat new to the software so please bear that in mind.
Source 1 | Source 2 | Source 3
| Next Day; Ground; 2 Day | Next Day; Ground; 2 Day | Next Day; Ground; 2 Day
+Manager 1|
Rep 1 |
Rep 2 |
+Manager 2|
Rep 1 |
Rep 2 |
Looks like the best solution for you is to create bookmarks. You can create two tables, one showing the values and the other showing the %. Position the tables such that, one table is exactly on top of the other. Then create two bookmarks, one showing Table1 and the other showing Table2 (while hiding the other table using the "Selection Pane"). You can then use the bookmarks in a button action to toggle between Value and % views. The following link should give you further details on bookmarks:
https://learn.microsoft.com/en-us/power-bi/desktop-bookmarks
You can also do this by creating a measure which switches between values and %, but the formatting is going to be a pain point. I think bookmarks is your best bet.
You can create a parameter table (with no relationships to other tables in your model) to use as a slicer and a measure that switches between the two calculations based on a slicer selection.
Let's suppose you have measures [OrderCount] and [OrderCount%Total]. Then create a new table to use as a parameter ParamMeasure with a single column
Measure
-------
Count
%Total
You can now put ParamMeasure[Measure] as a slicer on your report and substitute the following measure instead of the existing ones.
OrderSwitch =
IF (
SELECTEDVALUE ( ParamMeasure[Measure] ) = "Count",
[OrderCount],
[Order%Total]
)
This way you don't need to create multiple visuals and bookmarks.

How to divide each row of a calculated column by the total of another calculated column?

I can't get a division correct with this sample data:
Calculated column Another calc. column
48 207
257 370
518 138
489 354
837 478
1,005 648
1,021 2,060
1,463 2,164
2,630 1,818
2,993 2,358
3,354 3,633
4,332 5,234
4,885 6,108
4,514 6,008
4,356 6,888
4,824 7,382
7,082 5,988
7,498 6,059
4,865
4,192
3,816
2,851
2,768
2,093
2,207
770
397
149
178
336
167
124
18
What I'm trying to do is to create a new calculated column.
For each row I want to get the value of Calculated column and divide it by the Total of Another calc. column.
The Total of Another calc. column = 82826
This is the desired output in a brand new calculated column, let's call it % Column:
% Column
0,000579528167484
0,003102890396735
0,006254074807428
.
.
.
NOTE - these 3 columns: Calculated column, Another calc. column and % Column are all in the same table and are all calculated columns.
I tried lots of formulas but not a single one returned the desired output. :| I guess it's because of the nature of calculated columns or I'm not getting the gist of it.
Is this even possible or I should follow another path using a Measure?
Can you shed some light?
####### EDIT #######
I put together a sample file to help debugging this. Here it is:
https://drive.google.com/open?id=1r7kiIkwgHnI5GUssJ6KlXBAoeDRISEuC
As you see:
Earned Daily % HARDCODED works just fine because 82826 is hardcoded as the denominator.
Earned Daily % by StelioK and Earned Daily % by Alexis Olson output the same wrong value for the division when using SUM formula.
I'm using the latest Power BI Desktop version if that matters: Version: 2.70.5494.701 64-bit (June 2019)
Basically, there is nothing wrong with the calculated columns, and both Alexis and StelioK formulas are correct.
The root problem here is a confusion between calculated columns and measures. You are looking at the results in a conceptually wrong way - through the matrix visual, with several filters active on slicers. If you remove the filters, you will see that the total amount is 140,920, not 82,826. The latter number is the total for the filtered data set, not the entire table.
To get this right, you need to understand several fundamental concepts behind Power BI:
Calculated columns are always static. Once a calculation is
completed, it can not respond to slicers or other UI controls. It's
just static data, identical to data in non-calculated columns. DAX
formulas used to calculate columns are active only when you create
them, or upon data reload.
If you want your calculations to respond to slicers etc, they must be measures. It's the only way, no exceptions.
Avoid calculated columns, they are utterly useless. Power BI is all about measures; I can't think of a single reason for using calculated columns. When you add a column, you are essentially enhancing your source data, because you feel like you are missing something you need for your report. But that need can be much better addressed at the source (database or file you import), or using Power Query, which is designed exactly for this kind of tasks. The best practice is: build your columns at the source, for everything else design measures.
Another important advice: never drop fields (columns) into visuals directly. Always write a DAX measure, and then use it. Relying on Power BI auto-aggregations is a very bad practice.
You can do this by using the following DAX:
% Column =
VAR TotalSum =
SUM ( 'Table'[Another Calc column] )
RETURN
IF (
NOT ( ISBLANK ( 'Table'[Calc Column] ) ),
CALCULATE ( DIVIDE ( SUM ( 'Table'[Calc Column] ), TotalSum ) ),
0
)
Which yields the following:
I Hope it helps!!
For me the following works:
DIVIDE( Table1[Calculated column], SUM(Table1[Another calc column]) )
If that's not working, I'd need to see a file where you can reproduce the problem.
Edit: After looking at your file, the total of 82,826 is only true with the filters you've selected.
Note that calculated columns are not dynamic and cannot be responsive to filters since they are calculated only when the table is first loaded.
If you need it to be dynamic, then write it as a measure more like this:
Earned Daily =
DIVIDE (
CALCULATE (
SUM ( 'Test data'[Value] ),
'Test data'[Act Rem] = "Actual Units",
'Test data'[Type] = "Current"
),
CALCULATE (
SUM ( 'Test data'[Value] ),
ALLSELECTED ( 'Test data' ),
'Test data'[Act Rem] = "Remaining Units",
'Test data'[Type] = "PMB"
)
)

Power BI cumulative count with multiple condition

Did anyone know how to convert RunningCount into Power bi Dax ?
I test on RunningTotal, Rankx but seems not working.
The [year] is just a text column not in Datetime format.
I still new on this and not sure if my explain is good enough or not. Sorry for any inconvenient cause.
I try to create measure/ calculation column in power bi from the formula below.
I need the count by Year, break by column like product, customer, rate and category.
Before I get into my solution, there are a few assumptions I had to make:
The "Year" column is supposed to be years, and not five digit numbers. So in my data I dropped the second "2" in each (i.e. "20213" -> "2013").
You may have another column in your data to break ties, but given the data you provided, there is no way to rank the first and third lines (they both have product ABC and year 2003).
Given those assumptions, here is my solution...
First, here is what my data looks like. I added an ID column so that we can see every row, even duplicates.
From there, you can simply add a new column with the following formula.
Running Count =
COUNTROWS(
FILTER(
'Data',
[ProductName] = EARLIER([ProductName]) &&
[Customer] = EARLIER([Customer]) &&
[Seller] = EARLIER([Seller]) &&
[Year] <= EARLIER([Year])
)
)
The EARLIER function is being used to specify a ProductName, Customer, etc. from the row of the table to be used in the filtering of the data. Once we have the data filtered, we can simple count the number of rows.
The final result looks like this. As noted in my second assumption, there is no way to break ties, so my numbers are slightly off from what you have in your screenshot