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
Asmilinich25
Regular Visitor

Creating a Distinct Column Count of a Column Based on Another Column Data

Hi All, 

I have been struggling to find the solution for this. I have an imported data set where column one has a unique identifier that may be repeated for multiple rows. The other column I have is the date which is translated into a week of month column. See below:

 

Unique IdentifierDateWeek of MonthDistinct Count Week 1Distinct Count Week 2Distinct Count Week 3Distinct Count Week 4

1XY100000

1/312NullNullNull
1XY1000001/512NullNullNull
1XY1000011/712NullNullNull
1XY1000011/712NullNullNull
1XY1000011/712NullNullNull
1XY1000021/102Null2NullNull
1XY1000031/112Null2NullNull
1XY1000031/112Null2NullNull
1XY1000041/173NullNull1Null
1XY1000041/183NullNull1Null
1XY1000051/254NullNullNull2
1XY1000061/254NullNullNull2

 

What I would like to accomplish is to create a column which shows the distinct count in the "Unique Identifier" for the rows that include "Week of Month"=1. 

Currently I have it to where if the "Week of Month"=1 then it will report the distinct count of the entire unique identifier row only next to the "Week of Month" rows that =1. This is what Im currently working with:

 

= if [Week of Month]=1 then List.NonNullCount(List.Distinct(#"Promoted Headers"[Unique Identifier])) else Null

 

This give me what you see in "Distinct Count Week 1" column with the exception that the number displayed is "7" which is the distinct count for the entire "Unique Identifier" row. 

 

How do I get this to display a distinct count "Unique Identifier" of only the rows where "Week of Month"=1? 

 

*Distinct count columns are the outputs I am looking to get from my table data using Power Query.

 

Any insight on the solution is appreciated. Thanks!

2 REPLIES 2
Asmilinich25
Regular Visitor

KT, 

Thank you for the reply. When I input this in and adjust it to my sheet I am not quite getting the right result. 

For me this reported the row count for each individual "Unique Identifier" in it's respecitve row. In other words it reported the following: 

Unique IdentifierDateWeek of MonthDistinct Count Week 1Distinct Count Week 2Distinct Count Week 3Distinct Count Week 4

1XY100000

1/312NullNullNull
1XY1000001/512NullNullNull
1XY1000011/713NullNullNull
1XY1000011/713NullNullNull
1XY1000011/713NullNullNull
1XY1000021/102Null1NullNull
1XY1000031/112Null2NullNull
1XY1000031/112Null2NullNull
1XY1000041/173NullNull2Null
1XY1000041/183NullNull2Null
1XY1000051/254NullNullNull1
1XY1000061/254NullNullNull1

 

What I was looking for was it to search in "Week of Month" column and if Week of Month=1 report back the distinct number of Unique identifer numbers in the Unique Identifier column into the created column. So for Week 1 there are two unique identifiers in column 1 (1XY100000 & 1XY100001). So I would want the output in the created column to be "2"  for all rows being that distinctly 2 unique identifiers were found in rows where Week of Month=1.

 

Thank you in advance for anything else you may suggest. 

 

KT_Bsmart2gethe
Impactful Individual
Impactful Individual

Hi @Asmilinich25 ,

 

Add a custom column and add the code below:

*replace the #"Changed Type" with your previous step name.

Table.SelectRows( 
   Table.Group(
      #"Changed Type", 
      {"Unique Identifier"}, 
      {
        {"Count", 
         each Table.RowCount(Table.Distinct(_)), 
         Int64.Type}
      }
   ), 
   (x)=> [Unique Identifier] = x[Unique Identifier] 
)[Count]{0}

 

Regards

KT

 

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