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
p-ha
Frequent Visitor

Countif in Power BI

Hi all, I'm fairly new to Power BI and still trying to grasp the logic behind all the DAX and how to utilize them. Any help is greatly appreciated!

 

Here is my sample data table:

POItem #DescriptionLocationYearSupplier
100AA1Apple-GreenSTA0102017Supplier A
101AA2Apple-RedSTA0102018Supplier A
102BB1Banana-YellowSTA0102017Supplier B
103BB1Banana-YellowSTA0202018Supplier A
104BB2Banana-GreenSTA0302019Supplier C
105BB2Banana-GreenSTA0402017Supplier A
106BB3Banana-PinkSTA0302019Supplier B
107BB3Banana-PinkSTA0102017Supplier B
108CC1Candy-GreenSTA0102018Supplier A
109CC2Candy-RedSTA0102019Supplier A
110CC3Candy-YellowSTA0202018Supplier C
111CC4Candy-BlueSTA0302017Supplier B
112DD1Doll-GreenSTA0102019Supplier A
113DD1Doll-GreenSTA0302018Supplier B
114DD2Doll-BlueSTA0202017Supplier C
115DD2Doll-BlueSTA0402018Supplier C
116DD3Doll-RedSTA0102019Supplier A
117DD3Doll-RedSTA0402018Supplier B
118DD4Doll-PinkSTA0102017Supplier A
119DD4Doll-PinkSTA0302018Supplier A
120DD5Doll-YellowSTA0302019Supplier C
121DD5Doll-YellowSTA0202017Supplier A
122DD5Doll-YellowSTA0402019Supplier C

 

What I'm trying to achieve: (below is the result I got from Excel by running pivot table counting total PO per year per each item and countif on the side table)

 

My goal: 

- count/% of total item with transaction (PO) > 2 in each year and illustrate on canvas as the sum table (right) below.

 

 201720182019G. Total  item with transaction > 2   
AA11  1 20170   
AA2 1 1 20180   
BB111 2 20191   
BB21 12      
BB31 12      
CC1 1 1      
CC2  11      
CC3 1 1      
CC41  1      
DD1 112      
DD211 2      
DD3 112      
DD411 2      
DD51 23      
           

 

Thank you in advance for your help!

New.Bee.P.

2 ACCEPTED SOLUTIONS
dax
Community Support
Community Support

Hi p-ha,

 

According to your description, it seems that you want to get below result, right(if count(po)>1, then show 1 in Year)?

57.png

If so, you could use below measure to see whether it work or not

Measure 5 =
IF (
    CALCULATE (
        COUNT ( test[PO] ),
        FILTER (
            test,
            test[Item #] = MAX ( test[Item #] )
                && test[Year] = MAX ( test[Year] )
        )
    ) > 1,
    1,
    0
)

 

Best Regards,

Zoe Zhi

 

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

Ashish_Mathur
Super User
Super User

Hi,

This measure works

Measure = COUNTROWS(FILTER(SUMMARIZE(VALUES(Data[Item #]),Data[Item #],"ABCD",COUNTROWS(Data)),[ABCD]>1))+0

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

This measure works

Measure = COUNTROWS(FILTER(SUMMARIZE(VALUES(Data[Item #]),Data[Item #],"ABCD",COUNTROWS(Data)),[ABCD]>1))+0

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
dax
Community Support
Community Support

Hi p-ha,

 

According to your description, it seems that you want to get below result, right(if count(po)>1, then show 1 in Year)?

57.png

If so, you could use below measure to see whether it work or not

Measure 5 =
IF (
    CALCULATE (
        COUNT ( test[PO] ),
        FILTER (
            test,
            test[Item #] = MAX ( test[Item #] )
                && test[Year] = MAX ( test[Year] )
        )
    ) > 1,
    1,
    0
)

 

Best Regards,

Zoe Zhi

 

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.