Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Kiruthika0102
New Member

How to Display Measure-Based Buckets in Stacked Bar Chart Legend in Power BI?

Hi everyone,

I'm working on a Power BI report where I have:

  • A date slicer (from a calendar table)
  • A table of activities with an ACTIVITY_DATE
  • A measure that calculates the age in days by comparing each ACTIVITY_DATE with the selected slicer date
  • Based on that, I created a bucket measure to group records into:
    • "0-2 weeks" (0–14 days)
    • "3-4 weeks" (15–28 days)

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:

  • Since the bucket is calculated using a measure (due to dependence on slicer), I can’t add it to the Legend field.
  • I can't use a calculated column either, because it won’t react to the date slicer.

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!

 

1 ACCEPTED SOLUTION
v-karpurapud
Community Support
Community Support

Hi @Kiruthika0102 


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").

vkarpurapud_0-1746768639993.png

 

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!

 

 

View solution in original post

5 REPLIES 5
v-karpurapud
Community Support
Community Support

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.

v-karpurapud
Community Support
Community Support

Hi @Kiruthika0102 

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.

 

v-karpurapud
Community Support
Community Support

Hi @Kiruthika0102 

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.

v-karpurapud
Community Support
Community Support

Hi @Kiruthika0102 


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").

vkarpurapud_0-1746768639993.png

 

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!

 

 

BeaBF
Super User
Super User

@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


💡 Did I answer your question? Mark my post as a solution!

👍 Kudos are appreciated

🔥 Proud to be a Super User!

Community News image 1920X1080.png

 

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

Check out the May 2025 Power BI update to learn about new features.

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.