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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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

Top Solution Authors