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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
WAB_Reports
Helper I
Helper I

Unique count of a column in a measure with Countrows Filter and GroupBy in use?

Hello all,

 

I'm struggling with how to get a count of Unique "Unit Plate" based on the data below, with countrows a filter and groupby using "AGE YEARS" >2 and Tires = "OLD".

 

UNIT TYPEUNIT PLATECOLOURTIRESAGE Years
CARXYZ1REDNEW1
CARXYZ1REDNEW1
CARXYZ36BLUEOLD5
CARXYZ400REDOLD6
CARXYZ5BLUENEW2
CARXYZ1BLUEOLD5
CARXYZ9GREENNEW3
CARXYZ9GREENNEW3
CARXYZ400REDOLD6

 

The table is much larger than this and if I do a manual filter (with just the above data) the value comes back as 3 (Age Years??) instead of 4.

 

Secondary quick question: is there a step through available in Power Bi? Would be awesome to have the ability to see your table change as you compose the query / measure etc.

1 ACCEPTED SOLUTION
WAB_Reports
Helper I
Helper I

Hmm now I have an issue with accepting the solutions, I combo'd both to get what I needed. 🙂

 

I ended up with:

 

CountUniquePlates = CALCULATE(DistinctCount('Table'[UNIT PLATE]), FILTER('Table', 'Table'[AGE Years]> 2 && 'Table'[TIRES] ="OLD"))

 

Thank you to all who replied.

View solution in original post

3 REPLIES 3
WAB_Reports
Helper I
Helper I

Hmm now I have an issue with accepting the solutions, I combo'd both to get what I needed. 🙂

 

I ended up with:

 

CountUniquePlates = CALCULATE(DistinctCount('Table'[UNIT PLATE]), FILTER('Table', 'Table'[AGE Years]> 2 && 'Table'[TIRES] ="OLD"))

 

Thank you to all who replied.

mahoneypat
Employee
Employee

Please try this expression

 

NewMeasure = CALCULATE(DISTINCTCOUNT(Table[Unit Plate]), Table[Age Years]>2, Table[Tires] = "Old")

 

There is not a DAX editor like the query editor (that would be greate); however, you can approach that by visualing your filter/table expressions using a DAX table and/or breaking up your expressions into variables and "return"ing each individually to troubleshoot.  This expression doesn't need either, but for more complex queries those approaches come in very handy.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


NamishB
Post Prodigy
Post Prodigy

Hi @WAB_Reports - Try below measure:

 

CountMeasure = CALCULATE(Count('Table'[UNIT PLATE]), FILTER('Table', 'Table'[AGE Years]> 2 && 'Table'[TIRES] ="Old"))

 

This will give you output as 4. 

 

Hope this helps.

 

Cheers,

-Namish B

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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