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
The_Clam
Helper I
Helper I

Count of ID if column A is greater than 25 or column B is greater than 250

Hi.  I need some help please.  

I would like a count of ID if column A is greater than 25 or column B is greater than 250. The two tricky parts I cannot quite grasp are: 1) If both conditions are TRUE, then it should only count as 1, not 2.  And 2) There are duplicate IDs in the dataset, so the SUM of these IDs should be above the thresh-hold, not individually.

I have attached a link to the Power BI file.  For the dataseset in the file, the number I am looking for is: 24

Thanks!

Power BI file: 

https://drive.google.com/file/d/11GRAerF7N79UY-OrOX_7DqzrpktoLLc6/view?usp=sharing

 

Small sample of dataset:

IDAB
28483300
2862901469905
2863101469907
28987400
28989500
2902380
2903580
2920310
2920510
2921310
2921510
2934380
2942910
2943380
29441140
29441130

 

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

Hi  @The_Clam ,

Here are the steps you can follow:

1. Create calculated table.

Table =
FILTER('Worksheet','Worksheet'[A]>25 || 'Worksheet'[B]>250)

Table Create calculated column:

count =
COUNTX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])),[ID])

vyangliumsft_0-1653292965120.png

2. Create measure.

Flag =
var _Count1=COUNTX(FILTER(ALL('Table'),'Table'[count]=1),[ID])
var _Count2=COUNTX(FILTER(ALL('Table'),[count]=3),[ID])
var _Count3 =
CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER(ALL('Table'),'Table'[count]=2))
return
_Count1 + _Count2 - _Count3

3. Result:

vyangliumsft_1-1653292965122.png

If you need pbix, please click here.

Not very clear the meaning of thresh-hold, here I use the number of each group to distinguish.

 

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

1 REPLY 1
v-yangliu-msft
Community Support
Community Support

Hi  @The_Clam ,

Here are the steps you can follow:

1. Create calculated table.

Table =
FILTER('Worksheet','Worksheet'[A]>25 || 'Worksheet'[B]>250)

Table Create calculated column:

count =
COUNTX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])),[ID])

vyangliumsft_0-1653292965120.png

2. Create measure.

Flag =
var _Count1=COUNTX(FILTER(ALL('Table'),'Table'[count]=1),[ID])
var _Count2=COUNTX(FILTER(ALL('Table'),[count]=3),[ID])
var _Count3 =
CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER(ALL('Table'),'Table'[count]=2))
return
_Count1 + _Count2 - _Count3

3. Result:

vyangliumsft_1-1653292965122.png

If you need pbix, please click here.

Not very clear the meaning of thresh-hold, here I use the number of each group to distinguish.

 

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

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.