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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
luke6363
Frequent Visitor

Error with bar chart visual SummarizeColumns() and AddMissingItems() may not be used in this context

I have a list of companies. The companies have products categorized by product code. What I'm trying to do is select a company (or multiple) in a slicer and see the count of products that other companies have in the same product code as the selected company (or multiple). The below DAX works great for that in a simple card, but if I use it in a barchart for example so I can visualize the count by product code, then I get the error SummarizeColumns() and AddMissingItems() may not be used in this context. Please help!

Measure =
CALCULATE(

    DISTINCTCOUNT('TableA'[productid]),

    SUMMARIZECOLUMNS('TableA'[product_code],

    FILTER('TableA','TableA'[company_name] IN VALUES('TableB'[company_name]))))

1 ACCEPTED SOLUTION

hi  @luke6363 

For your requirment, you could try these two measure:

including = 
CALCULATE(COUNTA(TableA[ProductID]),FILTER(ALL(TableA), TableA[Product Code] IN VALUES(TableA[Product Code])))
not including = 
CALCULATE(COUNTA(TableA[ProductID]),FILTER(ALL(TableA), TableA[Product Code] IN VALUES(TableA[Product Code])))-CALCULATE(COUNTA(TableA[ProductID]))

Result:

2.JPG

 

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@luke6363 , what are you trying to achieve using SUMMARIZECOLUMNS?

Try like

Measure =
CALCULATE(

DISTINCTCOUNT('TableA'[productid]),

FILTER('TableA','TableA'[company_name] IN VALUES('TableB'[company_name])))

@amitchandak I'm not trying to just count the unique productid's for a given company. I'm trying to count the unique productid's that match the product_code's of the given company. 

 

Example Data Below. I want to select Acme in a slicer, and then count how many unique product id's match the product codes of Acme. So Acme's product codes are AA and BB, so the count of unique product id's that match those product codes is 4 (including Acme) or 2 (not including Acme)

ProductIDProduct CodeCompany
12AAAcme
13AAGlobex
42BBAcme
11BBInitech
121CCInitech

hi  @luke6363 

For your requirment, you could try these two measure:

including = 
CALCULATE(COUNTA(TableA[ProductID]),FILTER(ALL(TableA), TableA[Product Code] IN VALUES(TableA[Product Code])))
not including = 
CALCULATE(COUNTA(TableA[ProductID]),FILTER(ALL(TableA), TableA[Product Code] IN VALUES(TableA[Product Code])))-CALCULATE(COUNTA(TableA[ProductID]))

Result:

2.JPG

 

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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