I am working with PowrBi Dax and I have to add a KPI, which should be rather simple but I am struggling. Let me give you some context first:
I have a data set that includes provinces, hospitals and a score for every hospital (the score is measure I have already calculated (Score Patient Journey)).
Province | Hospital | Score Patient Journey (measure) |
---|---|---|
A | D | 0.1 |
A | E | 0.5 |
A | F | 0.8 |
B | G | 0.6 |
C | H | 1 |
In the dashboard I have a slicer with the Provinces and underneath a table that shows all hospitals within the selected provinces and their scores.
The hospitals can be grouped in three different groups, depending on their score. So a hospital would belong to the first group if its score is >=0 and <0.5. A hospital would belong to the second group if its score is >= 0.5 and <0.6. And the third group includes hospitals that have a score >= 0.6.
Now I need to add a KPI for the third group. This KPI should show the percentage of hospitals that belong to the third group compared to all hospitals within the province selected.
In easier words, if province A is selected in the slicer, the KPI should show: [Number of Hospitals belonging to the third group in province A] / [Number of all hospitals belonging to province A]
-> taking the sample data from the table above it would mean 1 / 3 = 0.333, since we have one hospital belonging to the thrid group out of the three hospitals in that province.
If province B is selected in the slicer, the KPI should show 1/1 = 1, since there is only one hospital in this province and it belongs to the third group.
Another thing that is crucial is that, when the users clicks a hospital in the table, the KPI should not change. It should solely depend and be filtered on province.
I tried this, but it doesnt work.
VAR table_ =
ADDCOLUMNS(FILTER(‘data’, [Score Patient Journey]>=0.6),
“Value”, [Score Patient Journey])
VAR table1 =
ADDCOLUMNS(table_,
“percentage”, countx(table_, [Hospital]) / count(‘data'[Hospital]))
Var selectedhospital= SELECTEDVALUE(‘data'[Hospital])
Return minx(filter(table1, ‘data'[Hospital]=selectedhospital), [percentage]