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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Miss_A
Regular Visitor

List.distinct function

= Table.Group(#"Replaced Errors2", {"Sr", "ClinicName", "Month", "age_group", "sex", "dignosis", "Diagnosis_group", "LabCombine.Final Result", "PreTBForm.Screening", "Final Screening Result", "ScreeningResultForDB", "Code"}, {{"UniquedCount", each Table.RowCount(List.Distinct(_[Code])), Int64.Type}})

 

I wirte above function in power query but is only count all the rows are 1. how to cout for the duplicate code

1 ACCEPTED SOLUTION

Apologies!  I misunderstood the problem.  Please try this instead.

jennratten_0-1703158002189.png

Code for the example above:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUbIwMTI2MDA2NTRRitWBCxkZGBgYmhgiCwFVGRmYW6IJGZpZmBAWMrAwBwrFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Age Group" = _t, Code = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Age Group", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Age Group", "Code"}, {{"CodeCount", each List.Count ( _[Code] ), type nullable number}})
in
    #"Grouped Rows"

 For your table:

Table.Group(#"Replaced Errors2", {"Sr", "ClinicName", "Month", "age_group", "sex", "dignosis", "Diagnosis_group", "LabCombine.Final Result", "PreTBForm.Screening", "Final Screening Result", "ScreeningResultForDB", "Code"}, {{"UniqueCount", each List.Count(_[Code]), type nullable number}})

View solution in original post

5 REPLIES 5
Miss_A
Regular Visitor

Expression.Error: We cannot convert the value 1 to type List.
Details:
Value=1
Type=[Type]

Miss_A
Regular Visitor

It does not work. In code column Code: 01,02,03,04,05,02,03, 05. The fomula show only 1, not 

84230035141
84220001411
84230020791
84230016841
84230016841
84230008741

 

How is work?

 

Apologies!  I misunderstood the problem.  Please try this instead.

jennratten_0-1703158002189.png

Code for the example above:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUbIwMTI2MDA2NTRRitWBCxkZGBgYmhgiCwFVGRmYW6IJGZpZmBAWMrAwBwrFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Age Group" = _t, Code = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Age Group", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Age Group", "Code"}, {{"CodeCount", each List.Count ( _[Code] ), type nullable number}})
in
    #"Grouped Rows"

 For your table:

Table.Group(#"Replaced Errors2", {"Sr", "ClinicName", "Month", "age_group", "sex", "dignosis", "Diagnosis_group", "LabCombine.Final Result", "PreTBForm.Screening", "Final Screening Result", "ScreeningResultForDB", "Code"}, {{"UniqueCount", each List.Count(_[Code]), type nullable number}})
jennratten
Super User
Super User

Hello - if you are trying to identify duplicate values in the Code column it would be like this:

Table.Group(#"Replaced Errors2", {"Sr", "ClinicName", "Month", "age_group", "sex", "dignosis", "Diagnosis_group", "LabCombine.Final Result", "PreTBForm.Screening", "Final Screening Result", "ScreeningResultForDB"}, {{"UniquedCount", each List.Count(List.Distinct([Code])), type nullable number}})

It does not work. In code column Code: 01,02,03,04,05,02,03, 05. The fomula show only 1, not 

84230035141
84220001411
84230020791
84230016841
84230016841
84230008741

 

How is work?

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors