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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
pmagadum
Frequent Visitor

DistinctCount with condition in Power Query

Hi

I have a measure created in DAX 

Measure1 = CALCULATE(DISTINCTCOUNT(Fact_Details[Column3]),Fact_Details[Column2]="Core",Fact_Details[Column3]<>BLANK())

 

Im trying the same thing in Power Query

= Table.Group(Source, {"Column1", "Column2"}, {{"Measure1", each List.Count(List.Distinct(_[Column3])), Int64.Type} })

 

Is this correct? How do i calcualte distinctcount of a coumn with condition?

 

Thanks,

Pradeep

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @pmagadum ,

 

Try this code

= Table.Group(#"Changed Type", {"Column2"}, {{"Count", each Table.RowCount(Table.Distinct(Table.SelectRows(_, each [Column3]<>""))), Int64.Type}})

 

Before

vstephenmsft_0-1640854648379.png

After

vstephenmsft_1-1640854663467.png

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
AlexisOlson
Super User
Super User

The distinct count part looks fine.

 

You can add those extra conditions as a filter before doing the Group By.

What if ?

= Table.Group(Source, {"Column1", "Column2"}, {{"Measure1", each List.Count(List.Distinct(_[Column3])), Int64.Type}, {"Measure2", each List.Count(List.Distinct(_[Column4])), Int64.Type} })

 

Scenario:

If Column2="Core" then distinct count of Column3

If Column2="Non Core" then distinct count of Column4

 

In this case i cannot filter the rows before doing the group by. 

Anonymous
Not applicable

Hi @pmagadum ,

 

Try this code

= Table.Group(#"Changed Type", {"Column2"}, {{"Count", each Table.RowCount(Table.Distinct(Table.SelectRows(_, each [Column3]<>""))), Int64.Type}})

 

Before

vstephenmsft_0-1640854648379.png

After

vstephenmsft_1-1640854663467.png

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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 Solution Authors