How to use parameters for a report to refresh at runtime - powerbi

I am calculating the score and weight of a result based on a target result and conditions for two measures. These is the dataset I have
GroupName Measure1 Measure2
Group1 0.8 0.7
Group2 0.4 0.8
Currently I am calculating the Score & Weight using two different if functions, like
Measure1 Weight Score =
var kk=IF(
'Sprints'[Velocity%_NEW] > 0.85,
"5",
IF(
'Sprints'[Velocity%_NEW] < 0.85 && 'Sprints'[Velocity%_NEW] >0.7,
"3",
If('Sprints'[Velocity%_NEW] < 0.7,"1"
)))
Return kk *0.5
What I am want is when a user use the report and asked to input the parameter for GroupName then the Score and Weight should change automatically by the value set for each GroupName and calculate the result? any help apperciated.

You can use parameters here. Refer: Create or edit a report parameter
In top header ribbon, choose Modeling and click on “What If” parameter
create a new parameter, what-if parameter screenshot to set the type and range of value that users can input. This will add a slicer to the page where user can choose.
Create a measure to interact with your report. You can add in your calculation for the result to be with your existing data and the user input(add parameter reference in your weight calculation measure).
Simple Example to multiply the source data with the input value from user:
Measure = [Parameter Value]*CALCULATE(SUM(Table1[Value]))
you can also create a measure to view the parameter selected using as below
Parameter Value = SELECTEDVALUE(Parameter[Parameter])

Related

How to solve this chart line example in PWBI or Power BI?

Obs:
The final database has 40 countries, 5 regions and range 2008:2018. Here's a small example of the base to illustrate the problem in Pibx file.pbix.
The idea consists in a dynamic chart, which will be update according to user interaction, as follow some examples:
When opening the dashboard, the first screen that the user would see would already be this one with all filters active/selected and show on the chart line the result of [Filter avg %YOY Region] between the period from 2008 to 2011 (due it is active) already starting the option {Avg National} enabled.
Now, suppose that the user clicks on the value {P1} in [Value by Country] to view the corresponding result of [Avg % YoY] on the chart and wants to compare this result with all years . The result of this selection would be:
Now, suppose that the user clicks on the value {P1} in [Value by Country] to view the corresponding result of [Avg % YoY] on the chart and wants to compare this result with all measures of [Filter avg %YOY Region]. The result of this selection would be:
Now, suppose that the user clicks on the value {P1} and {P2} in [Value by Country] to visualize the result of [Avg % YoY] of the respective filters on the chart line and wants to compare the results with the mean {Avg SE } in [Filter avg %YOY Region]. The result of this selection would be:
Applying the same logic to other possible ideas including the year filter.
How does Pwbí manage to do this wrong account? Mean (19.72 - 2.02) = 10.41?
In a measure each cell is recalculated. So the measure for SE is not calculated by averaging the measure at the P2 and P3 grain. If it did, then P2 and P3 would always be equally weighted, which isn't normally what you want.
Instead the measure is recalculated for the SE grain.

Use TREATAS to pass constant to a measure with CALCULATE

I created a what-if parameter in a PowerBI desktop report called 'Default Target'[Default Target] which ranges from 0.8 to 1 in 0.001 increments.
Default Target = GENERATESERIES(0.8, 1.0, 0.001)
The what if parameter also built a measure for me called [Default Target Value] which is meant to return the SELECTEDVALUE() of the parameter, or its default value as the alternate result:
Default Target Value = SELECTEDVALUE('Default Target'[Default Target], 0.94)
I want to present [MyFancyMeasure], but prescribe certain [Default Targets] and load them into table columns for comparison. So I built several measures to use CALCULATE and TREATAS to get the results, as in this example:
CAR_86 = CALCULATE( [MyFancyMeasure], TREATAS({{0.86}},'Default Target'[Default Target]) )
but this didn't give me the expected result (I was expecting it to use 86% as the selected value of [Default Target], not 94%).
Instead, it returns all rows based on the <alternateResult> of the selectedvalue measure:
Why is [CAR_86] not aligning with the actual selectedvalue of the what-if parameter slicer, and also not aligning to the filtered value from the TREATAS function?
How can I effectively pass a constant to [MyFancyMeasure] so I don't have to rewrite the entire measure for each constant I want to present?
Also: I tried to filter the default target table in the calculate like this but it does the same thing:
CAR_86 = CALCULATE( [Default Target Value], FILTER(ALL('Default Target'),[Default Target]=0.86) )

Filtering other tables based on cross-highlighting a filtered measure

I want to count records in a certain condition and allow people to filter down to the relevant records, but selecting a measure value (which filters so it only counts certain rows) isn't cross-filtering others as I'd expect. Maybe ths isn't possible or maybe I'm just doing it wrong, but I'd appreciate help.
I have a single table:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wci4tLsnPTS1SMFTSUTJUitVBEjICChmgChljCplgajSFCMUCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Customer Name" = _t, #"Ordered Recently" = _t]),
#"Change to INT" = Table.TransformColumnTypes(Source,{{"Ordered Recently", Int64.Type}}),
#"Change to T/F" = Table.TransformColumnTypes(#"Change to INT",{{"Ordered Recently", type logical}})
in
#"Change to T/F"
The result looks like this:
Customer Name Ordered Recently
Customer 1 True
Customer 2 False
Customer 3 False
Customer 4 True
Customer 5 True
I added two measures:
Count Total = COUNTROWS(Customers)
Count Recent = CALCULATE([Count Total], filter(Customers, Customers[Ordered Recently]))
If I put both measures in a bar chart and highlight the "Count Recent" measure, I'd expect it to know to filter other visuals based on the FILTER statement present in the measure, but that doesn't happen. Selecing this value doesn't impact anything else on my page (including just a count of rows).
The goal is to allow people to select a measure that counts rows and then to see the makeup of the data in those rows (select a count of late projects and filter other visuals to describe those late projects).
Is this possible or am I doing something wrong?
EXAMPLE:
Here's what it looks like now, with nothing selected:
When I select the black bar (the "Ordered Recently" measure), nothing changes right now - but here's what I want to happen (actually achieved with a slicer off screen on the T/F field):
I understand if my measure is a SUM of an integer field, it includes every row in the calculation - even when the row value is zero - and there's no way to filter my dataset based on that. However, in this case, my measure is actually using a FILTER on the dataset so that it only counts rows with a certain criteria set - given that, it should be able to filter the requested table, and then flow that filter through the rest of my dataset (the same way it would if I selected a bar from a chart where I had used that same field as the series - exactly how it works when I do this:
PBIX file to download as an example
No, I don't believe it's possible to make a measure value cross-filter other visuals based on filters within the measure definition.
You can, however, click on i.e. row header Customer 3 and it should cross-filter the other visuals to only include that customer. Any table column you set for the rows or columns of a matrix visual should behave this way.
Here's a hacky workaround:
Create a measure that shows the right values when you use the column you want to use as a filter as the Legend or Axis (like in your last image). For example, in this case, you could do this:
Total Customers =
VAR TF = SELECTEDVALUE ( Customers[Ordered Recently] )
RETURN
COUNTROWS (
FILTER (
ALLSELECTED ( Customers ),
IF ( TF, TF, TF || Customers[Ordered Recently] )
)
)
This behaves how you want, but isn't labeled as you want. To achieve that create a calculated column with the labels you want. For example,
Label = IF(Customers[Ordered Recently], "Ordered Recently", "Total Customers")
Then take Ordered Recently off the axis and put the Label column in the Legend box to get this:
Your Filter argument is really Filter(All(Customers, Customers[Ordered Recently])
You remove all filters on the Customer Table, and then specify Ordered Recently Column as the filter.
Try
[MeasureName] =Calculate([Count Total], All(Customer), Values(Customer[Recently Ordered]), Customer[Recently Ordered] = “True”)

Can I pass custom value to the calculated column in Power BI?

I want to append custom value to the calculated column which is already created in Power BI.
I have created below switch statement by creating new column 'Income Verification Type' in Power BI:
Income Verification Type =
SWITCH (
TRUE (),
HoldCode[HoldCode] <> "SELFCM", "Fully Verified",
HoldCode[HoldCode] = "SELFCM", "Self Certified"
)
Got the below result as expected -
Income Verification Type
Fully Verified
Self Certified
But I want the result as below. I want to include or append the new value (Fast-track) to the above column.
Income Verification Type
Fully Verified
Self Certified
Fast-Track
There must be some DAX functions which should helps me to append the custom value to existing column.

Power BI Dashboard where the core filter condition is a disjunction on numeric fields

We are trying to implement a dashboard that displays various tables, metrics and a map where the dataset is a list of customers. The primary filter condition is the disjunction of two numeric fields. We want to the user to be able to select a threshold for [field 1] and a separate threshold for [field 2] and then impose the condition [field 1] >= <threshold> OR [field 2] >= <threshold>.
After that, we want to also allow various other interactive slicers so the user can restrict the data further, e.g. by country or account manager.
Power BI naturally imposes AND between all filters and doesn't have a neat way to specify OR. Can you suggest a way to define a calculation using the two numeric fields that is then applied as a filter within the same interactive dashboard screen? Alternatively, is there a way to first prompt the user for the two threshold values before the dashboard is displayed -- so when they click Submit on that parameter-setting screen they are then taken to the main dashboard screen with the disjunction already applied?
Added in response to a comment:
The data can be quite simple: no complexity there. The complexity is in getting the user interface to enable a disjunction.
Suppose the data was a list of customers with customer id, country, gender, total value of transactions in the last 12 months, and number of purchases in last 12 months. I want the end-user (with no technical skills) to specify a minimum threshold for total value (e.g. $1,000) and number of purchases (e.g. 10) and then restrict the data set to those where total value of transactions in the last 12 months > $1,000 OR number of purchases in last 12 months > 10.
After doing that, I want to allow the user to see the data set on a dashboard (e.g. with a table and a graph) and from there select other filters (e.g. gender=male, country=Australia).
The key here is to create separate parameter tables and combine conditions using a measure.
Suppose we have the following Sales table:
Customer Value Number
-----------------------
A 568 2
B 2451 12
C 1352 9
D 876 6
E 993 11
F 2208 20
G 1612 4
Then we'll create two new tables to use as parameters. You could do a calculated table like
Number = VALUES(Sales[Number])
Or something more complex like
Value = GENERATESERIES(0, ROUNDUP(MAX(Sales[Value]),-2), ROUNDUP(MAX(Sales[Value]),-2)/10)
Or define the table manually using Enter Data or some other way.
In any case, once you have these tables, name their columns what you want (I used MinNumber and MinValue) and write your filtering measure
Filter = IF(MAX(Sales[Number]) > MIN(Number[MinCount]) ||
MAX(Sales[Value]) > MIN('Value'[MinValue]),
1, 0)
Then put your Filter measure as a visual level filter where Filter is not 0 and use MinCount and MinValues column as slicers.
If you select 10 for MinCount and 1000 for MinValue then your table should look like this:
Notice that E and G only exceed one of the thresholds and tha A and D are excluded.
To my knowledge, there is no such built-in slicer feature in Power BI at the time being. There is however a suggestion in the Power BI forum that requests a functionality like this. If you'd be willing to use the Power Query Editor, it's easy to obtain the values you're looking for, but only for hard-coded values for your limits or thresh-holds.
Let me show you how for a synthetic dataset that should fit the structure of your description:
Dataset:
CustomerID,Country,Gender,TransactionValue12,NPurchases12
51,USA,M,3516,1
58,USA,M,3308,12
57,USA,M,7360,19
54,USA,M,2052,6
51,USA,M,4889,5
57,USA,M,4746,6
50,USA,M,3803,3
58,USA,M,4113,24
57,USA,M,7421,17
58,USA,M,1774,24
50,USA,F,8984,5
52,USA,F,1436,22
52,USA,F,2137,9
58,USA,F,9933,25
50,Canada,F,7050,16
56,Canada,F,7202,5
54,Canada,F,2096,19
59,Canada,F,4639,9
58,Canada,F,5724,25
56,Canada,F,4885,5
57,Canada,F,6212,4
54,Canada,F,5016,16
55,Canada,F,7340,21
60,Canada,F,7883,6
55,Canada,M,5884,12
60,UK,M,2328,12
52,UK,M,7826,1
58,UK,M,2542,11
56,UK,M,9304,3
54,UK,M,3685,16
58,UK,M,6440,16
50,UK,M,2469,13
57,UK,M,7827,6
Desktop table:
Here you see an Input table and a subset table using two Slicers. If the forum suggestion gets implemented, it should hopefully be easy to change a subset like below to an "OR" scenario:
Transaction Value > 1000 OR Number or purchases > 10 using Power Query:
If you use Edit Queries > Advanced filter you can set it up like this:
The last step under Applied Steps will then contain this formula:
= Table.SelectRows(#"Changed Type2", each [NPurchases12] > 10 or [TransactionValue12] > 1000
Now your original Input table will look like this:
Now, if only we were able to replace the hardcoded 10 and 1000 with a dynamic value, for example from a slicer, we would be fine! But no...
I know this is not what you were looking for, but it was the best 'negative answer' I could find. I guess I'm hoping for a better solution just as much as you are!