Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi everyone,
I'm working on a Power BI report where I have:
Now, I have a stacked bar chart where the X-axis is an organization category (e.g., Org1, Org2, etc.). I want to show, for each organization, how many records fall into the "0-2 weeks" and "3-4 weeks" buckets.
The problem is:
Is there a recommended method or workaround to make these measure-based buckets appear in the legend or to achieve this kind of breakdown in a stacked bar chart?
Thanks in advance!
Solved! Go to Solution.
Thank you for reaching out to the Microsoft Fabric Community Forum. Also, thank you @BeaBF for you quick response.
Regarding your issue with displaying measure-based buckets in a stacked bar chart legend in Power BI, please use a disconnected table for the buckets and a dynamic measure to calculate the counts.
Disconnected Table
Buckets =
DATATABLE(
"Bucket", STRING,
"MinDays", INTEGER,
"MaxDays", INTEGER,
{
{"0-2 weeks", 0, 14},
{"3-4 weeks", 15, 28}
}
)
Create a Measure to Calculate Activities per Bucket
Activities per Bucket =
VAR SelectedDate = COALESCE(SELECTEDVALUE('Calendar'[Date]), TODAY())
VAR CurrentBucket = SELECTEDVALUE('Buckets'[Bucket])
RETURN
IF(
ISBLANK(CurrentBucket),
0,
CALCULATE(
COUNTROWS('Activities'),
FILTER(
'Activities',
NOT ISBLANK('Activities'[ACTIVITY_DATE]) &&
VAR AgeInDays = DATEDIFF('Activities'[ACTIVITY_DATE], SelectedDate, DAY)
VAR BucketMin = CALCULATE(MIN('Buckets'[MinDays]), 'Buckets'[Bucket] = CurrentBucket)
VAR BucketMax = CALCULATE(MAX('Buckets'[MaxDays]), 'Buckets'[Bucket] = CurrentBucket)
RETURN
AgeInDays >= BucketMin && AgeInDays <= BucketMax
)
)
)
Add a Stacked Bar Chart visual to your report and drag the Bucket field from the Buckets table. This will split the bars by bucket (e.g., "0-2 weeks", "3-4 weeks").
If the chart doesn’t accept the measure, delete the visual and create a new stacked bar chart, then reconfigure it as described above.
If you are still unable to use the measure, consider using a stacked column chart instead of a stacked bar chart.
If this response resolves your query, kindly mark it as Accepted Solution to help other community members. A Kudos is also appreciated if you found the response helpful.
Thank You!
Hi @Kiruthika0102
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
Thank you for reaching out to the Microsoft Fabric Community Forum. Also, thank you @BeaBF for you quick response.
Regarding your issue with displaying measure-based buckets in a stacked bar chart legend in Power BI, please use a disconnected table for the buckets and a dynamic measure to calculate the counts.
Disconnected Table
Buckets =
DATATABLE(
"Bucket", STRING,
"MinDays", INTEGER,
"MaxDays", INTEGER,
{
{"0-2 weeks", 0, 14},
{"3-4 weeks", 15, 28}
}
)
Create a Measure to Calculate Activities per Bucket
Activities per Bucket =
VAR SelectedDate = COALESCE(SELECTEDVALUE('Calendar'[Date]), TODAY())
VAR CurrentBucket = SELECTEDVALUE('Buckets'[Bucket])
RETURN
IF(
ISBLANK(CurrentBucket),
0,
CALCULATE(
COUNTROWS('Activities'),
FILTER(
'Activities',
NOT ISBLANK('Activities'[ACTIVITY_DATE]) &&
VAR AgeInDays = DATEDIFF('Activities'[ACTIVITY_DATE], SelectedDate, DAY)
VAR BucketMin = CALCULATE(MIN('Buckets'[MinDays]), 'Buckets'[Bucket] = CurrentBucket)
VAR BucketMax = CALCULATE(MAX('Buckets'[MaxDays]), 'Buckets'[Bucket] = CurrentBucket)
RETURN
AgeInDays >= BucketMin && AgeInDays <= BucketMax
)
)
)
Add a Stacked Bar Chart visual to your report and drag the Bucket field from the Buckets table. This will split the bars by bucket (e.g., "0-2 weeks", "3-4 weeks").
If the chart doesn’t accept the measure, delete the visual and create a new stacked bar chart, then reconfigure it as described above.
If you are still unable to use the measure, consider using a stacked column chart instead of a stacked bar chart.
If this response resolves your query, kindly mark it as Accepted Solution to help other community members. A Kudos is also appreciated if you found the response helpful.
Thank You!
@Kiruthika0102 Hi! you can achieve this breakdown using a disconnected table as a legend proxy and a SWITCH-based measure.
1. Create a disconnected table:
AgeBuckets = DATATABLE(
"Bucket", STRING,
{
{"0-2 weeks"},
{"3-4 weeks"}
}
)
2. Create a measure:
ActivityCountByBucket =
VAR SelectedBucket = SELECTEDVALUE(AgeBuckets[Bucket])
RETURN
SWITCH(
TRUE(),
SelectedBucket = "0-2 weeks",
CALCULATE(
COUNTROWS(Activities),
FILTER(
Activities,
[Age in Days] >= 0 && [Age in Days] <= 14
)
),
SelectedBucket = "3-4 weeks",
CALCULATE(
COUNTROWS(Activities),
FILTER(
Activities,
[Age in Days] >= 15 && [Age in Days] <= 28
)
),
BLANK()
)
3. Build the visual with:
X-axis: Organization category
Legend: AgeBuckets[Bucket]
Values: ActivityCountByBucket
BBF
User | Count |
---|---|
19 | |
15 | |
15 | |
13 | |
13 |
User | Count |
---|---|
13 | |
12 | |
11 | |
8 | |
7 |