Forum Discussion

p-ha's avatar
p-ha
Frequent Visitor
7 years ago
Solved

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.

  • 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)?

    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.

  • Hi,

    This measure works

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

    Hope this helps.

2 Replies

  • dax's avatar
    dax
    Icon for Community Support rankCommunity 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)?

    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.

  • Hi,

    This measure works

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

    Hope this helps.