问题
I want to create a visualisation from a dataset which shows percentages that change accordingly when filters are used.
I have a dataset like the below but with over 1 million rows of data covering 18 months. All the fields are text except Month which is a date and SUMofAPPTS which is numerical.
SUPP GEOG1 MODE STATUS TYPE TIME Month Day SUMofAPPTS
AA 00D Face Att 1 1 Day 2018-06 Sun 12
AA 00D Face Att 1 1 Day 2018-06 Mon 119
AA 00D Face Att 1 4 Unk 2018-06 Tues 98
BB 00D Tel DNA 2 1 Day 2018-06 Weds 98
BB 00D Online DNA 3 1 Day 2018-06 Thurs 126
CC 00D Face DNA 1 2 Day 2018-07 Sun 8
I would like a measure which calculates the percentage of SUMofAPPTS by Day and MODE (and the same but for STATUS, TYPE and TIME) which changes when filters are placed on the other fields.
So I think I need to make this simple calculation (which would work in a column if I just wanted to know the percentage per row of the whole dataset) more dynamic so that it works when I filter the data:
PERCENT = 'dataset'[SUMofAPPTS]/SUM('dataset'[SUMofAPPTS])
The end result will be a stacked bar chart with the following attributes:
- Day as the Axis
- PERCENT as the Value
- MODE, STATUS, TYPE or TIME as the Legend
- Ability to filter by one, many or all of the fields except Day and SUMofAPPTS
回答1:
First, create a measure for aggregating SUMofAPPTS:
Total APPTS = SUM(Data[SUMofAPPTS])
Second, create a measure for the percentage:
APPTS % of Selected
= DIVIDE(
[Total APPTS],
CALCULATE([Total APPTS], ALLSELECTED()))
This measure recalculates [Total APPTS] ignoring all filters except those selected by a user (on slicers etc).
Result:
after selections:
Edit
If you need to breakdown by Day (or any other field), you can re-introduce filters like this:
APPTS % of Selected
= DIVIDE(
[Total APPTS],
CALCULATE([Total APPTS], ALLSELECTED(), VALUES(Data[Day])))
来源:https://stackoverflow.com/questions/56272781/power-bi-measure-to-calculate-percentage-which-changes-with-filters