Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I am working on a stacked bar chart in Power BI, where I need to show the year along with the total count of jobs (formatted like "SurveyYear (N = xx)"). I want the count to dynamically adjust when a slicer for NameCategory is applied.
Here is the DAX formula I am using to format the count for each SurveyYear:
DAX
FORMAT(vw_Questionnaire[Year], "") & " (N = " & UNICHAR(160) & FORMAT(CALCULATE(count(TableName[TotalJob]),
FILTER(TableName, TableName[Year] = EARLIER(TableName[Year]))), "") & ")"
This formula works as expected but when I select any of the NameCategory in slicer N = ## does not change, So I add the NameCategory filter, like this:
DAX
FORMAT(TableName[Year], "") & " (N = " & UNICHAR(160) & FORMAT(CALCULATE(count(TableName[TotalJob]),
FILTER(TableName, TableName[Year] = EARLIER(TableName[Year])),
FILTER(TableName, TableName[NameCategory] = EARLIER(TableName[NameCategory]))), "") & ")"
... it causes the stacked bar chart to divide into multiple categories for each NameCategory.
I want to keep all NameCategory values aggregated into one bar per Year like stacked bar chart, and display the total count of jobs for the selected year & NameCategory.
Hi @Anonymous ,
Is my follow-up just to ask if the problem has been solved?
If so, can you accept the correct answer as a solution or share your solution to help other members find it faster?
Thank you very much for your cooperation!
Hi @Anonymous
Use this DAX formula to ensure the count dynamically updates without splitting the stacked bar chart:
FORMAT(TableName[Year], "") & " (N = " & FORMAT(
CALCULATE(
COUNT(TableName[TotalJob]),
ALLSELECTED(TableName[NameCategory]) -- Keeps aggregation across all NameCategory
), ""
) & ")"
This keeps the bars aggregated while dynamically adjusting the total count based on slicer selections.
Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂
Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Please Subscribe my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
Hi,
I recommend using the data label to achieve this:
E.g.
data:
Measures:
Now the labels react to slicers
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/
Proud to be a Super User!
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
10 | |
6 |