Whatif Analysis with Measure - powerbi

I have created a What-if analysis where i am deciding the Threshold value to it. 
I have an margin% and Actual Margin % and i need to compare both these value with the value of the Threshold.
Like, Threshold= 20%
         margin= 3.90%
         Actual Margin %= 0.65%
So, i have created a measure where i am calculating the Actual Margin % with Threshold value i.e. x=0.65*20%
Now i need to compare it(x) with the margin i.e. if(margin
I am able to get this both the measure in place but unable to get the final measure with color code.
Note: Threshold level can be changed and the x value should be changed accordingly with the final color code as well.

Create a Parameter called Threshold: min 1 max 100 step 1 (create also the slider by setting the radio button)
Threshold = GENERATESERIES(0; 100; 1)
Create a measure:
Measure = if (SUM('Values'[ Value]) > Threshold[Parameter Value];"Green";"Red")
Add the measure to the table visual and go to the format tool. Go to conditional formatting. select the measure from the combo and set the Background color on.
Now you get a popup. Set to field value and the column to measure.
Result: when sliding your values will change:

Related

DAX to calculate max of all visible monthly totals for all series in a chart

I have a "Line and clustered column chart" in Power BI where the bars are actual values and line is budgeted values. Actual and budgeted values often vary enough that their Y axis scaling doesn't match, so I need both axes to have the same scale. Start value for both could be zero, but End needs to be calculated. We need to dynamically calculate End based on the visible data within the chart. My approach so far has been to create a measure that calculates the highest monthly actual value and another measure that calculates the highest monthly budget value, then take that max of those two measures and use it in a function for the "End" value of both Y axes. I have not found the DAX that works yet.
Example of y axes with different scaling and the max value we want
I suspect I'll need to get the min and max dates that are selected in the visual, and the following measures give me those:
MinSelectedDate = CALCULATE(MIN('Date'[CalendarDate]), ALLSELECTED('Date'))
MaxSelectedDate = CALCULATE(MAX('Date'[CalendarDate]), ALLSELECTED('Date'))
I also suspect I'll need to build a table within the measure and summarize the values then iterate over that table to find the max. Somthing like this:
MaxActual = MAXX(
SUMMARIZE(ALLSELECTED('FactActualValues'), 'Date'[FirstDayOfMonth], "Volume", [Actual Values]),
[Actual Volumes]
)
However, when I try this DAX the data ends up being sliced by the month within each year. I'm using a matrix for dev/test.
Dev/test using matrix
The optimal solution is to have an analytical model with two columns (Date and FY).
Cancel dynamization of the table, setting the years to the "Year" column and converting it to Text type
Create the column "Month" from the month number of "MonthName" and convert to type Text
Create the date column of the format dd-mm-yyyyy from the concatenation using "01/"+[Month]+"/"+[Year]
Format the new date column to date format
The y-axis scale is resolved by the "Clustered Column Chart" visualization as it takes the maximum value of a single column of values plus some margin at the top and takes that as the y-axis value.
Got it! I was very close but didn't need to calculate min or max dates. Using ALLSELECTED gave me just the records from the FactActualValues table that I needed without applying an explicit filter. I also learned that some functions (e.g. - MAX) cannot "see" columns returned by table functions, but others like MAXX do support it. SUMMARIZE allows you to create a column and I learned that some people use the empty single quote to reference such a column.
Here's the DAX that works:
MaxMonthlyActual =
MAXX(
SUMMARIZE(
ALLSELECTED('FactActualValues'),
'Date'[FirstDayOfMonth],
"#ActVol", SUM('FactActualValues'[Total])
),
''[#ActVol]
)
Here is what the chart looks like using the DAX measure:
Chart with Y axes with matching scales

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

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.

Can we calculate a measure with percentage in Power BI matrix

Can we create a percentage measure in power BI over a matrix visual.
You can create a measure in your table using DAX below -
% Percentage = DIVIDE([1],[0])
Then change the format of [% Percentage] to percentage
You can create this below measure-
%percentage = DIVIDE(your_table_name[1],your_tabl_name[0])
Now change the Type of the Measure as % from the top menu.
Try this, if it helps. I am throwing blank if denominator is blank else it's value will become invalid:
Create a measure and append that next to your matrix.
Measure = IF(COUNT(Sheet1[Denominator])<COUNT(Sheet1[Numerator]), BLANK(), DIVIDE(SUM(Sheet1[Numerator]), SUM(Sheet1[Denominator])))
Later you can change formatting from right side, below visualization, where you see small dropdowns next to column/row/values names > Show values as.
Let me know if it solves your problem.

PBI - How to group by column name in pie chart along percentage (with values displayed)?

I'm having trouble with use group by on pie chart - maybe it can be done differently.
I have a simple pie chart with only 2 values: Name, and their values (grouped by the Name).
The values are an amount and not a percentage. (The percentage may be displayed as well, but only if the amount will be displayed also).
And I need to somehow (I guess with group by) rename all the Names where the percentage ratio in this chart lower than, for example, 10% to a different string, like Group_with_10per_or_lower.
Any ideas how this can be done?
For example, imagine having States and their values of something. USA = 350; Canada = 250, Brazil = 200, Argentina = 150, Chile = 50. And what you have is a pie chart with these data. But you need to rename all states having 20% or less ratio of this value (Brazil, Argentina, and Chile) as Other for example. So you would have the pie chart with USA, Canada, and Other (Brazil + Argentina + Chile) but still have their values displayed in the chart and not their %. It can be both, but not just %.
Let's say you have a table Table1(state, value)
Create a measure:
Total = CALCULATE(SUM(Table1[value]),All(Table1))
Create a calculated column:
state2 = IF([value]<[total]*0.2,"Other",[state])
Use state2 in your visualisation.

Power BI chart to highlight and compare any three periods of data

Does Power BI have a chart that can highlight to compare three periods? In this case, they are current month, previous month, and the same period last year.
I have the three measures ready but couldn't find a chart type to highlight the periods I want to compare and grey out the rest.
I believe the key here is using a measure on the chart's color saturation field.
I was able to achieve the following where the bar colors are dependent on the date slicer:
I defined my measure like this:
Color =
VAR SelectedDate = SELECTEDVALUE(Cal[Month])
RETURN 0.5*(EOMONTH(SelectedDate, -12) IN VALUES(MTS[Date])) +
0.8*(EOMONTH(SelectedDate, -3 ) IN VALUES(MTS[Date])) +
1*(EOMONTH(SelectedDate, 0 ) IN VALUES(MTS[Date]))
where MTS is a monthly time series table and Cal is an unrelated calendar table that only has month ends. Only one of the conditions holds at a time and the constants in front just define where on the color range the result will land when the condition returns TRUE() (which gets coerced to be 1 when multiplying).
Once you've put a measure on the color saturation field, you can access the data color settings under the Format section:
If you are just looking to highlight three measures manually to distinguish from the others you can go into the Format tab, and under "Data colors" you can toggle on the "Show all" option and change them there.
You could also use a slicer.