Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
I have two tables namely category and sales. The category table contains categoryName, categoryID, and subcategoryIDs (which is unique). The sales table contanis the subcategoryID and sales date.
The sales tables is connected to the category table via subcategoryid. ( One to many relation)
1) I have created a calculated column called count of subcategoryID in the category table which basically counts the occurence of each subcategory ID in the sales table.
count of subcategoryID = COUNTROWS(RELATEDTABLE(sales))
2) I have created another calculated column called New Category Name which sums up the values from the column created above based on category ID . If SUM is < 5, then the value is "Other", else we retain the Category Name.
Here's the code:
New Category Name = IF(CALCULATE (
SUM ('category'[count of subcategoryID] ),
FILTER (
ALL ( 'category' ),
'category'[categoryID] = EARLIER('category'[categoryID])
)
) < 5, "Other", 'category'[category name])
I have a pie chart which displays the New Category Name based on the sales dates. I also have a date slicer for sales date. The problem is, when I change the date slider, the pie chart displays the CategoryName of categories whose count is less than 5 instead of labelling them as "other" and counting them in the "Other" bucket.
I am assuming the issue is because the calculated column New Category Name has the calculation for the entire span of sales dates instead of the date range selected in the slider. How can I dynamically change New Category Name based on slider dates ?
@sieed wrote:
I have two tables namely category and sales. The category table contains categoryName, categoryID, and subcategoryIDs (which is unique). The sales table contanis the subcategoryID and sales date.
The sales tables is connected to the category table via subcategoryid. ( One to many relation)
1) I have created a calculated column called count of subcategoryID in the category table which basically counts the occurence of each subcategory ID in the sales table.
count of subcategoryID = COUNTROWS(RELATEDTABLE(sales))
2) I have created another calculated column called New Category Name which sums up the values from the column created above based on category ID . If SUM is < 5, then the value is "Other", else we retain the Category Name.
Here's the code:New Category Name = IF(CALCULATE (
SUM ('category'[count of subcategoryID] ),
FILTER (
ALL ( 'category' ),
'category'[categoryID] = EARLIER('category'[categoryID])
)
) < 5, "Other", 'category'[category name])
I have a pie chart which displays the New Category Name based on the sales dates. I also have a date slicer for sales date. The problem is, when I change the date slider, the pie chart displays the CategoryName of categories whose count is less than 5 instead of labelling them as "other" and counting them in the "Other" bucket.
I am assuming the issue is because the calculated column New Category Name has the calculation for the entire span of sales dates instead of the date range selected in the slider. How can I dynamically change New Category Name based on slider dates ?
Yes, the calculated column won't vary according to slicer selection. You can take some tricks by using measures to show [category name] or "Other" values, but you can't use that as a legend/details in a pie chart.
@Eric_Zhang, what are the tricks? Wold appreciate if you can share some more info.
@sieed wrote:
@Eric_Zhang, what are the tricks? Wold appreciate if you can share some more info.
The trick is like creating a measure as below
@sieed, did you created new columns or measures? Based on formulas, seems like you added new measures. Can you share some sample data to help provide the solution? Thanks
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
What happens if you use ALLEXCEPT like this:
New Category Name = IF(CALCULATE (
SUM ('category'[count of subcategoryID] ),
FILTER (
ALLEXCEPT ( 'category', 'category'[Date] ),
'category'[categoryID] = EARLIER('category'[categoryID])
)
) < 5, "Other", 'category'[category name])
Where 'category'[Date] is your date field and the date used in your slicer.
@Anonymous, there is no category date in the category table. There i showever sales_date in the sales table. Do you want me to use that instead?
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
105 | |
99 | |
98 | |
38 | |
37 |
User | Count |
---|---|
154 | |
120 | |
73 | |
73 | |
63 |