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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
grkanth81
Helper II
Helper II

Not able to use measure in the legend of a bar chart. Any alternatives ?

Hi all,

I have created a DateTable to show last 7 days data as below:

DateTable = CALENDAR(TODAY()-7, TODAY()-1)
and there is a date slicer which shows last 7 dates. when the user selects any date, it should show a bar chart displaying count of employees per department and in the legend it should display how many employees target met and target not met. Here is the criteria for Target: If SUM of hours worked is greater than or equal to distinct dailytarget then Target reached else Target not reached. And when no date is selected, it should show how many employees have worked more than sum of distinct daily target?
 
EmployeeIDDateValueDepartmentdailytargethoursworked
10011/08/2025HR7.51
10011/08/2025HR7.57
10012/08/2025HR7.57
10013/08/2025HR7.57
10013/08/2025HR7.51.1
10014/08/2025HR7.57
10014/08/2025HR7.52.8
10015/08/2025HR7.57
10016/08/2025HR0NULL
10017/08/2025HR0NULL
20011/08/2025Finance60.3
20011/08/2025Finance65
20012/08/2025Finance65
20012/08/2025Finance61
20013/08/2025Finance61.5
20013/08/2025Finance64
20014/08/2025Finance62
20014/08/2025Finance63
20014/08/2025Finance61.5
20015/08/2025Finance62.5
20015/08/2025Finance61
20015/08/2025Finance61.5
20016/08/2025Finance0NULL
20017/08/2025Finance0NULL
30011/08/2025HR7.57.5
30012/08/2025HR7.56
30013/08/2025HR7.57.5
30014/08/2025HR7.57.5
30015/08/2025HR7.53
30015/08/2025HR7.55
30016/08/2025HR0NULL
30017/08/2025HR0NULL
40011/08/2025Finance7.51
40011/08/2025Finance7.57
40012/08/2025Finance7.57
40013/08/2025Finance7.57
40013/08/2025Finance7.51.1
40014/08/2025Finance7.57
40014/08/2025Finance7.52.8
40015/08/2025Finance7.57.5
40016/08/2025Finance0NULL
40017/08/2025Finance0NULL
 
And I have created a calculated table as below to get the summarised data from the above:
Table = SUMMARIZE(EmployeeTable,EmployeeTable[EmployeeID],EmployeeTable[DailyTarget],EmployeeTable[Dept],EmployeeTable[DateValue],"SumOfHrs",SUM(EmployeeTable[hoursworked]))
 
from the above, I have created a new measure for the Target which goes - If sum of hours recorded is greater than or equal to sum of daily target the 'Target reached' else 'Target Not reached' so that I can use in the legend. But, I noticed that I cannot use measure in the legend.
 
Can someone provide any alternatives for this issue?
Thanks,
grkanth81
 
 
 
1 ACCEPTED SOLUTION
v-pnaroju-msft
Community Support
Community Support

Hi grkanth81,

Thank you for your follow up.

Please find attached a screenshot and the revised sample .pbix file to address the issue:

vpnarojumsft_0-1755711151026.png
We hope the information provided will help resolve the matter. Should you have any further queries, please feel free to contact the Microsoft Fabric community.

Thank you.

View solution in original post

10 REPLIES 10
v-pnaroju-msft
Community Support
Community Support

Hi grkanth81,

We would like to follow up and see whether the details we shared have resolved your problem.
If you need any more assistance, please feel free to connect with the Microsoft Fabric community.

Thank you.

Hi v-pnaroju-msft, sorry for the late reply. Yes that worked perfectly. Thanks again.

v-pnaroju-msft
Community Support
Community Support

Hi grkanth81,

Thank you for your follow up.

Please find attached a screenshot and the revised sample .pbix file to address the issue:

vpnarojumsft_0-1755711151026.png
We hope the information provided will help resolve the matter. Should you have any further queries, please feel free to contact the Microsoft Fabric community.

Thank you.

v-pnaroju-msft
Community Support
Community Support

Hi grkanth81,

Thank you for your follow-up.

As per my understanding, because the legend is driven by a measure and a disconnected table, sorting directly on the legend will not affect the department order. Please find attached the revised sample PBIX file in which we have created a new measure to calculate the total employee count across all statuses. We have placed this measure in the tooltips field well of the visualizations pane and then sorted the visual by total employee count in descending order.

We hope the information provided will help resolve the issue. Should you have any further queries, please feel free to contact the Microsoft Fabric community.

Thank you.

Thanks again for your reply v-pnaroju-msft. yes that's working for the sample dummy data I provided. But in my actual dashboard which has many records it is not working. I have added some more sample records to  get a better picture. I am not able to attach my pbix file. So here is the new sample data with more records. Any help is appreciated ?

EmployeeIDDateValueDepartmentdailytargethoursworked
10011/08/2025HR7.51
10011/08/2025HR7.57
10012/08/2025HR7.57
10013/08/2025HR7.57
10013/08/2025HR7.51.1
10014/08/2025HR7.57
10014/08/2025HR7.52.8
10015/08/2025HR7.57
10016/08/2025HR0 
10017/08/2025HR0 
20011/08/2025Finance60.3
20011/08/2025Finance65
20012/08/2025Finance65
20012/08/2025Finance61
20013/08/2025Finance61.5
20013/08/2025Finance64
20014/08/2025Finance62
20014/08/2025Finance63
20014/08/2025Finance61.5
20015/08/2025Finance62.5
20015/08/2025Finance61
20015/08/2025Finance61.5
20016/08/2025Finance0 
20017/08/2025Finance0 
30011/08/2025HR7.57.5
30012/08/2025HR7.56
30013/08/2025HR7.57.5
30014/08/2025HR7.57.5
30015/08/2025HR7.53
30015/08/2025HR7.55
30016/08/2025HR0 
30017/08/2025HR0 
40011/08/2025Finance7.51
40011/08/2025Finance7.57
40012/08/2025Finance7.57
40013/08/2025Finance7.57
40013/08/2025Finance7.51.1
40014/08/2025Finance7.57
40014/08/2025Finance7.52.8
40015/08/2025Finance7.57.5
40016/08/2025Finance0 
40017/08/2025Finance0 
50011/08/2025HR7.57.5
50012/08/2025HR7.58.5
50013/08/2025HR7.57
50014/08/2025HR7.58
50015/08/2025HR7.57.5
50016/08/2025HR0 
50017/08/2025HR0 
60011/08/2025HR77
60012/08/2025HR77
60013/08/2025HR77
60014/08/2025HR77.5
60015/08/2025HR77.5
60016/08/2025HR0 
60017/08/2025HR0 
70011/08/2025Finance7.52
70011/08/2025Finance7.56
70012/08/2025Finance7.52
70012/08/2025Finance7.52.5
70012/08/2025Finance7.51
70013/08/2025Finance7.54
70013/08/2025Finance7.51.1
70013/08/2025Finance7.52
70014/08/2025Finance7.57
70015/08/2025Finance7.52.5
70015/08/2025Finance7.54.5
70016/08/2025Finance0 
70017/08/2025Finance0 

 

 

v-pnaroju-msft
Community Support
Community Support

Thankyou, @jaineshp, for your response.

Hi grkanth81,

We appreciate your enquiry through the Microsoft Fabric Community Forum.

Based on my understanding, since measures cannot be placed in the Legend, a feasible workaround is to create a disconnected TargetStatus table and drive it with a measure that compares each employee’s total hours worked against the sum of distinct daily targets. Using this approach, the bar chart displays department counts split by target status. When a date is selected, it evaluates that specific day and when no date is selected, it evaluates the full 7 day window.

Please find attached the screenshots and a sample PBIX file, which may assist in resolving the issue:

vpnarojumsft_0-1755531129169.png

vpnarojumsft_1-1755531174589.png
We hope the information provided helps to resolve your concern. Should you have any further queries, please feel free to contact the Microsoft Fabric community.

Thank you.

Thank you v-pnaroju-msft. That worked. I have one more small question. How to sort it by departments showing with highest total count to lowest total count. I tried to change it here but it seems to be not working. Any ideas ?

grkanth81_0-1755557954957.png

 

grkanth81
Helper II
Helper II

Thanks Jaineesh. Yes calculated column seems to be working when any date is selected but it is not working when no date is selected. Can you please explain what do you mean by the below?

For handling the "no date selected" scenario, you'll need to add appropriate filter logic in your visual-level filters.

Hey @grkanth81,

When no date is selected in your slicer, the calculated column may not behave as expected because it's trying to evaluate against a blank or null date context.

 

Visual-Level Filter Solutions:

Option 1: Default Date Logic

  • Go to your visual's Filters pane
  • Add your Date field to visual-level filters
  • Set filter type to "Advanced filtering"
  • Configure condition: "is not blank" or "is not null"
  • This ensures the visual only shows data when dates are properly selected

Option 2: Modified Calculated Column Update your calculated column formula to handle blank dates:

 

TargetStatus =
IF(
ISBLANK([DateField]) || [SumOfHrs] = BLANK(),
"No Data Available",
IF([SumOfHrs] >= [DailyTarget], "Target Reached", "Target Not Reached")
)

 

Option 3: Visual Display Rules

  • In visual-level filters, add custom filter on your TargetStatus column
  • Exclude "No Data Available" or blank values
  • This prevents incomplete data from appearing in your legend

Option 4: Slicer Configuration

  • Configure your date slicer to have a default selection
  • Set it to show current month or current date by default
  • This eliminates the "no date selected" state entirely

Recommended Implementation: Combine Option 2 with Option 3 - modify the calculated column to handle blanks gracefully, then filter out incomplete records at the visual level.

 

Fixed? ✓ Mark it • Share it • Help others!


Best Regards,
Jainesh Poojara | Power BI Developer

jaineshp
Memorable Member
Memorable Member

Hey @grkanth81,


Here are some practical workarounds since Power BI doesn't allow measures in legend:

 

Solution 1: Calculated Column Approach

  • Add calculated column to your summarized table:

TargetStatus = IF([SumOfHrs] >= [DailyTarget], "Target Reached", "Target Not Reached")

 

 

  • Drag this column to Legend field in your bar chart
  • This gives you the exact functionality you're looking for

Solution 2: Matrix Visual Alternative

  • Create separate measures for target met/not met counts
  • Switch to matrix visual instead of bar chart
  • Shows department-wise breakdown with target status

Solution 3: Stacked Bar Configuration

  • Build calculated columns for each target status
  • Configure as stacked bar chart
  • Legend automatically displays target categories

Solution 4: Enhanced Tooltips

  • Keep standard bar chart showing department totals
  • Add target breakdown in tooltips using measures
  • Users see details on hover

Recommended Approach: Option 1 is your best bet - calculated columns work perfectly with legends and it's the cleanest solution for your requirement.

For handling the "no date selected" scenario, you'll need to add appropriate filter logic in your visual-level filters.

 

Fixed? ✓ Mark it • Share it • Help others!


Best Regards,
Jainesh Poojara | Power BI Developer

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.