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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Thad
Frequent Visitor

Custom Column Based on Distinct Count

I CANNOT believe that the answer to this question is NOWHERE to be found on the internet, but here we are. 

 

I am trying to create a custom column in Power Query with the contents depending on the distinct count in a certain column called "Organisationseinheit". The column has to have at least 5 different values in it to be used further.

If it was a measure, it'd go like this:

 

If(DISTINCTCOUNT('Fragenkatalog'[Organisationseinheit]) <5, "Keine Auswahlmöglichkeit", 'Fragenkatalog'[Organisationseinheit]))

 

For some reason, I can't find ANY explanation on how the syntax is supposed to work for distinct counts in power query formulas. Also, I cannot find any way to use the result of the "Count distinct rows"-function from the transform ribbon, since it gives you the desired result but there's seemingly no way to use that result any further. 

 

This is such a laughably simple task, what the hell am I doing wrong?!

1 ACCEPTED SOLUTION

That one gave me the following Error:

Expression.Error: A cyclic reference was encountered during evaluation.

 

I found a workaround tho by creating a custom column like this:

 

= Table.AddColumn(#"Gefilterte Zeilen", "Orgaeinheit Ausprägungen", each List.NonNullCount(List.Distinct(#"Gefilterte Zeilen"[Organisationseinheit])))

 

and then another custom column like this: 

 

= Table.AddColumn(#"Added Custom", "Orgaeinheit", each if [Orgaeinheit Ausprägungen] < 5 then "Keine Auswahlmöglichkeit" else [Organisationseinheit])

 

which gave me the desired outcome. 

 

Thanks anyway!

View solution in original post

3 REPLIES 3
j_ocean
Helper V
Helper V

There's probably a way to do it within one query using advanced editor, but it might be easier use the GUI:

 

  1. Referece Query A into Query B
  2. Group-By Query B to whatever you need
  3. Reference query A into Query C
  4. Merge C and B
  5. Disable load on A and B
Anonymous
Not applicable

if Table.RowCount(Table.Distinct(Fragenkatalog, {"ColumnName"})) <5 then "Keine Auswahlmöglichkeit" else  [Organisationseinheit]

 

--Nate

That one gave me the following Error:

Expression.Error: A cyclic reference was encountered during evaluation.

 

I found a workaround tho by creating a custom column like this:

 

= Table.AddColumn(#"Gefilterte Zeilen", "Orgaeinheit Ausprägungen", each List.NonNullCount(List.Distinct(#"Gefilterte Zeilen"[Organisationseinheit])))

 

and then another custom column like this: 

 

= Table.AddColumn(#"Added Custom", "Orgaeinheit", each if [Orgaeinheit Ausprägungen] < 5 then "Keine Auswahlmöglichkeit" else [Organisationseinheit])

 

which gave me the desired outcome. 

 

Thanks anyway!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors