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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
KimberlyH
Regular Visitor

Unique count of rows any order using two columns

Help please!

I have a data set that I am trying to count the unique number of rows that have the same data regardless of order. 
Sample below:

Column1Column2
AB
AB
CD
CD
BA
BA
DC
DC
1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@KimberlyH 

I take it that the number of unique rows in your example is 2, since (A,B) is considered equivalent to (B,A) etc.

 

You could write a measure like this:

Distinct Combinations = 
COUNTROWS ( 
    DISTINCT ( 
        SELECTCOLUMNS ( 
            YourTable,
            "Value1", MIN(YourTable[Column1], YourTable[Column2]),
            "Value2", MAX(YourTable[Column1], YourTable[Column2])
        )
    )
)

Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

3 REPLIES 3
OwenAuger
Super User
Super User

@KimberlyH 

I take it that the number of unique rows in your example is 2, since (A,B) is considered equivalent to (B,A) etc.

 

You could write a measure like this:

Distinct Combinations = 
COUNTROWS ( 
    DISTINCT ( 
        SELECTCOLUMNS ( 
            YourTable,
            "Value1", MIN(YourTable[Column1], YourTable[Column2]),
            "Value2", MAX(YourTable[Column1], YourTable[Column2])
        )
    )
)

Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
mahoneypat
Microsoft Employee
Microsoft Employee

You can use

 

Unique Count = COUNTROWS(SUMMARIZE(Table, Table[Column1], Table[Column2]))

 

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


smpa01
Super User
Super User

@KimberlyHcan be done using pqwry

let
    Source = Web.BrowserContents("https://community.powerbi.com/t5/Desktop/Unique-count-of-rows-any-order-using-two-columns/m-p/1640243#M658636"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE:nth-child(2) > * > TR > :nth-child(1)"}, {"Column2", "TABLE:nth-child(2) > * > TR > :nth-child(2)"}}, [RowSelector="TABLE:nth-child(2) > * > TR"]),
    #"Changed Type" = Table.TransformColumnTypes(#"Extracted Table From Html",{{"Column1", type text}, {"Column2", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Column1", type text}, {"Column2", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"Column1", "Column2"}, {{"ad", each _, type table [Column1=nullable text, Column2=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each let x=[ad], y= Table.AddIndexColumn(x, "Rep", 1, 1, Int64.Type) in y),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Column1", "Column2", "Rep"}, {"Column1", "Column2", "Rep"})
in
    #"Expanded Custom"

 

Capture.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.