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
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
Employee
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
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.