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
Arshadjehan
Helper I
Helper I

Count of Categories in related table including uncategorized rows

I have two related tables with items linked on Code column.

Table1(Code, Description, Scope)    [1 side of the relationship]

Table2(Category, Code, Status)       [* side of the relationship]

 

There are Three types of Status : Completed, In Process, Rejected

 

I want a DAX measure or calculated column to count number of codes in table1 based on categories in table2. If an item is not assigned a category, it must be counted in a new category called "Unknown".

 

Regards

 

1 ACCEPTED SOLUTION

@Arshadjehan 

 

You may use DAX below to add a calculated table.

Table =
UNION (
    SUMMARIZECOLUMNS (
        Table2[Status],
        "Count of items", DISTINCTCOUNT ( Table2[Code] )
    ),
    ROW (
        "Status", "Unknown",
        "Count of items", COUNTROWS ( EXCEPT ( VALUES ( Table1[Code] ), VALUES ( Table2[Code] ) ) )
    )
)

 

Community Support Team _ Sam Zha
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
Nathaniel_C
Super User
Super User

Hi @Arshadjehan ,

Maybe you could dummy up some pictures in Excel to show what you have, and what you are looking for?

 

Please read this post to get your question answered more quickly:

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

Nathaniel





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

Proud to be a Super User!




Hi @Nathaniel_C 

Here is the dummy data and required output

Table 1  
CodeDescriptionScope
A123xxxabc
A124yyyabc
A125zzzwyx
A123pppxyz
B123xxxabc
   
   
Table 2  
CodeCategoryStatus
A123Dummy CategoryCompleted
A123Dummy Category2Completed
A125Dummy Category3In Process
A124Dummy CategoryRejected
   
   
Output  
   
StatusCount of items 
Completed2 
In process1 
Rejected1 
Unknown1 

 

Note that Unknown is not an explicit defined category, rather it is count of all codes in Table1 (1-side of relationship) which are not in Table 2 (*-side of the relationship)

 

Thanks

@Arshadjehan 

 

You may use DAX below to add a calculated table.

Table =
UNION (
    SUMMARIZECOLUMNS (
        Table2[Status],
        "Count of items", DISTINCTCOUNT ( Table2[Code] )
    ),
    ROW (
        "Status", "Unknown",
        "Count of items", COUNTROWS ( EXCEPT ( VALUES ( Table1[Code] ), VALUES ( Table2[Code] ) ) )
    )
)

 

Community Support Team _ Sam Zha
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.