Forum Discussion
Flag Indicator doesn't work with Stacked Bar Chart
- 1 year ago
Hi abczpo1 ,
Thank you for reaching out to the Microsoft Community Forum.
As mentioned by FBergamaschi in his previous response, Please provide sample data with expected output based on sample data.
Regards,
Dinesh
Hi abczpo1 ,
It sounds like the issue is with the measure you're using for the bar chart's values. You're likely counting the raw rows in your data, which causes the chart to create separate records for each month when multiple are selected. To fix this, you need to create a new measure that specifically counts the number of aggregated monthly outcomes ("Hit" or "Do not Hit") rather than the underlying data points.
For a tool that uses DAX like Power BI, you can solve this with a few key measures. First, ensure you have your base KPI measure defined, which calculates your ratio.
KPI A = DIVIDE( SUM(YourTable[A_1]), SUM(YourTable[A_2]) )
Next, create the flag as a separate measure. This will be used in the chart's legend to dynamically categorize the results based on the context of each month and category.
Performance Flag = IF( [KPI A] >= 2, "Hit $2", "Do not Hit $2" )
The most important step is to create the measure that will go into the chart's Values field. This measure must count the number of unique monthly instances, not individual transaction rows. Using SUMMARIZE is an excellent way to create a virtual table of the relevant months and categories, which you can then count. Using a proper Calendar Table in your data model is highly recommended for this.
Monthly Instance Count = COUNTROWS( SUMMARIZE( YourTable, 'YourTable'[Category], 'Calendar'[YearMonth] ) )
Once these measures are ready, you can build your chart. Place your YourTable[Category] field on the Axis, drag the [Performance Flag] measure to the Legend, and use your new [Monthly Instance Count] measure for the Values. This configuration forces the calculation to first determine the status for each month within a category and then correctly count how many months fall into the "Hit" and "Do not Hit" groups, giving you a single, properly stacked bar per category across all selected months.
If you are using a different tool like Tableau, you can achieve the same logic by using a Level of Detail (LOD) expression to calculate the KPI for each specific month and category. You would then create your flag based on that LOD result and use a distinct count of months for the size of your bars, with the flag on the color mark.
Best regards,