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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
UsePowerBI
Post Prodigy
Post Prodigy

DISTINCT COUNT and GROUP BY

Hello

 

I have the data:

 

A101/01/2020
B202/01/2020
C303/02/2020
E404/02/2020
D505/03/2020
D606/03/2020

 

How can I calculate the distinct number of Col1, where Col2 is >2 and group the results by month?

 

So the result should be:

 

Jan=0

Feb=2

Mar=1

 

Thanks!

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @UsePowerBI ,

Here are the steps you can follow:

1. Create calculated column.

Month = MONTH('Table'[Date])

Month_mmm = FORMAT([Date],"mmm")

2. Create measure.

Measure =
var _2=CALCULATE(DISTINCTCOUNT('Table'[Column1]),FILTER('Table','Table'[Column2]>2&&'Table'[Month]=MAX('Table'[Month])))
return IF(_2=BLANK(),0,_2)

3. Result.

v-yangliu-msft_0-1606294043890.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @UsePowerBI ,

Here are the steps you can follow:

1. Create calculated column.

Month = MONTH('Table'[Date])

Month_mmm = FORMAT([Date],"mmm")

2. Create measure.

Measure =
var _2=CALCULATE(DISTINCTCOUNT('Table'[Column1]),FILTER('Table','Table'[Column2]>2&&'Table'[Month]=MAX('Table'[Month])))
return IF(_2=BLANK(),0,_2)

3. Result.

v-yangliu-msft_0-1606294043890.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

ryan_mayu
Super User
Super User

@UsePowerBI 

you can create a column

month = FORMAT('Table'[Column3],"mmm")

then create a measure

Measure = CALCULATE(DISTINCTCOUNT('Table'[Column1]),FILTER('Table','Table'[Column2]>2))+0

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@UsePowerBI , Create a measure like this

calculate(distinctcount(Table[col1]), filter(Table, Table[col2] >2))+0

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak 

 

Thanks but how do I group by Month and what is the '+0' part please?

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.