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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
OLM
Helper I
Helper I

DAX: A Distinct count challenge

Dear PBI community,

My DAX challenge: In a table I have an column A with X value which can apply to Column B with 2 Y values

Table_1

Column A Column B

X1             Y1

X1             Y2

X2             Y3

X2             Y3         

 

So I want is to create Column C that will show how many unique Y's are per unique X so it should look like this:

Column A Column B Column C

 

X1             Y1             2

 

X1             Y2             2

 

X2             Y3             1

 

X2             Y3             1

 

 

Ofcourse real data cannot be shared.

 

Many thanks for your wisdom 😉

 

1 ACCEPTED SOLUTION

Hi,

In my opinion, using this to create another column in another table is also doable by DAX.

However, the below is for creating the column in Power Query Editor.
Please check the below picture and the attached pbix file's Power Query Editor.

 

Jihwan_Kim_0-1687231435428.png

 

let
    Source = Data_Source,
    #"Grouped Rows" = Table.Group(Source, {"Column A"}, {{"Group", each _, type table [Column A=text, Column B=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Expected result", each Table.Group ( [Group], {"Column A"}, {{"Count", each Table.RowCount(Table.Distinct(_)), Int64.Type}} )),
    #"Expanded Group" = Table.ExpandTableColumn(#"Added Custom", "Group", {"Column B"}, {"Column B"}),
    #"Expanded Expected result" = Table.ExpandTableColumn(#"Expanded Group", "Expected result", {"Count"}, {"Count"})
in
    #"Expanded Expected result"

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Jihwan_Kim_0-1687144168963.png

 

 

Expected result CC =
VAR _filterbyColumnA =
    FILTER ( Data, Data[Column A] = EARLIER ( Data[Column A] ) )
VAR _summarizebyColumnB =
    SUMMARIZE ( _filterbyColumnA, Data[Column B] )
RETURN
    COUNTROWS ( _summarizebyColumnB )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Great @Jihwan_Kim 

 

My next Q: I want to pull this column to another table therefore require merging. This means I need this column coded in Power Query. 

 

Can you translate it into M code?

Best

Liam

Hi,

In my opinion, using this to create another column in another table is also doable by DAX.

However, the below is for creating the column in Power Query Editor.
Please check the below picture and the attached pbix file's Power Query Editor.

 

Jihwan_Kim_0-1687231435428.png

 

let
    Source = Data_Source,
    #"Grouped Rows" = Table.Group(Source, {"Column A"}, {{"Group", each _, type table [Column A=text, Column B=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Expected result", each Table.Group ( [Group], {"Column A"}, {{"Count", each Table.RowCount(Table.Distinct(_)), Int64.Type}} )),
    #"Expanded Group" = Table.ExpandTableColumn(#"Added Custom", "Group", {"Column B"}, {"Column B"}),
    #"Expanded Expected result" = Table.ExpandTableColumn(#"Expanded Group", "Expected result", {"Count"}, {"Count"})
in
    #"Expanded Expected result"

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Many thanks,  via power query I can merge, therefore :).

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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