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
eryan123
Frequent Visitor

PowerBI: Count values in a Matrix

Hello All, 

 

I am trying to figure out how to count the values inside a matrix in a measure. 

My raw data looks like this. I have a large number of values and a large number of categories that the Category Type can be. 

VALUE#Category Type
Value1Category 1
Value1Category2
Value2Category3
Value 2Category 3
Value 3Category 30

 

I would like to be able to identify if any duplicates exist per Value. 

For example, in a matrix it would look like:

 Category1Category2CategoryN
Value1Count of category1Count of category2Count of categoryN
Value2Count of category1Count of category2Count of categoryN
Value3Count of category1Count of category2Count of categoryN

 

So that my final data can look like:

 

 Is there any duplicate? 
Value 1No
Value2Yes
Value3No

 

I am interested in wrapping this up to a measure rather than show the visualization of the matrix in the report. 

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Note your example data has spaces in it that result in no duplicates.  Once those are removed in query, this measure expression works in a table visual with the Value# column to get your desired result.

 

Duplicates =
VAR summary =
    SUMMARIZE (
        CatTypes,
        CatTypes[Category Type],
        "@count"COUNT ( CatTypes[Category Type] )
    )
RETURN
    IF (
        COUNTROWS (
            FILTER (
                summary,
                [@count] > 1
            )
        ) > 0,
        "Yes",
        "No"
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
mahoneypat
Employee
Employee

Note your example data has spaces in it that result in no duplicates.  Once those are removed in query, this measure expression works in a table visual with the Value# column to get your desired result.

 

Duplicates =
VAR summary =
    SUMMARIZE (
        CatTypes,
        CatTypes[Category Type],
        "@count"COUNT ( CatTypes[Category Type] )
    )
RETURN
    IF (
        COUNTROWS (
            FILTER (
                summary,
                [@count] > 1
            )
        ) > 0,
        "Yes",
        "No"
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat 

Thank you for your reply. 

I am actually interested in the duplicates only. I would like to be able to identify those because they mean 2 failures have occurred. 
If only one failure occures(does NOT have a duplicate), I would like to exclude that. 

 

Just change the "No" part of the IF to BLANK().  Once you do that rows that do not have duplicates will automatically filtered out of the visual.  

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


AlB
Super User
Super User

Hi @eryan123 

Measures only return scalars, not tables. You can create a calculated table:

NewTable =
ADDCOLUMNS (
    DISTINCT ( Table1[Value] ),
    "IsThereDuplicate",
        VAR dupsFound_ =
            CALCULATE ( DISTINCTCOUNT ( Table1[Value] ) )
                > CALCULATE ( DISTINCTCOUNT ( Table1[Value] ) )
        RETURN
            IF ( dupsFound__, "Yes", "No" )
)

I would recommend a visual with a measure though

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

eryan123
Frequent Visitor

@AlB 

Thank you for your reply. 

Your calculated table is not referencing the categories. As of now, all the Values are showing that they have duplicates. 
The Values and Duplicates are also not the only columns in the table that I am referencing. 

 

Any recommendations? 

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.

Top Solution Authors