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
GoodMan85
Frequent Visitor

Help Me count

Hello guys,
i have a problem with my file, i can't make a count.
Specifically I should count how many items are of category "A" and "UP" from the table.
The fields where the "UP" state originates is the following:
KPI L-G = IF ([DIFF L-G] <0, "DWN", IF ([DIFF L-G]> 0, "UP", "INV"))
DIFF L-G = [Adv Jul] - [Adv Down]
Adv Down = CALCULATE (SUM ('SM-ABC Analysis' [Adv.]), 'SM-ABC Analysis' [Month] = "6")
Adv Jul = CALCULATE (SUM ('SM-ABC Analysis' [Adv.]), 'SM-ABC Analysis' [Month] = "7")

Thank you all

BI.PNG

1 ACCEPTED SOLUTION

Hi @GoodMan85 

I build a sample to have a test. 

1.png

Try this measure.

CountANeg = 
CALCULATE (
    DISTINCTCOUNT ( 'SM-ABC Analysis'[Codice Art] ),
    FILTER (
        'SM-ABC Analysis',
        'SM-ABC Analysis'[Classic QTY] = "A"
            && CALCULATE (
                [DIFF L-G],
                ALLEXCEPT (
                    'SM-ABC Analysis',
                    'SM-ABC Analysis'[Codice Art],
                    'SM-ABC Analysis'[Classic QTY]
                )
            ) > 0
    )
)

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

5 REPLIES 5
Greg_Deckler
Super User
Super User

@GoodMan85 Try using COUNTX(FILTER(...),...)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @GoodMan85 

I build a sample to have a test. 

1.png

Try this measure.

CountANeg = 
CALCULATE (
    DISTINCTCOUNT ( 'SM-ABC Analysis'[Codice Art] ),
    FILTER (
        'SM-ABC Analysis',
        'SM-ABC Analysis'[Classic QTY] = "A"
            && CALCULATE (
                [DIFF L-G],
                ALLEXCEPT (
                    'SM-ABC Analysis',
                    'SM-ABC Analysis'[Codice Art],
                    'SM-ABC Analysis'[Classic QTY]
                )
            ) > 0
    )
)

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

Thank you so much @v-rzhou-msft !

Great, working good.

@Greg_Deckler 

I tried to do as you suggested, I have no errors in the formula but it does not allow me to view any results.

 

CountANeg = COUNTX(FILTER('SM-Analisi ABC', 'SM-Analisi ABC'[Classe Qty] = "A"), [DIFF L-G] < 0)

 

Do you have any suggestions?

@GoodMan85 I'd need some sample data to test with, I don't want to hand type in a bunch of data.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.