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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
ohnothimagain
Helper I
Helper I

DAX- Addcolumn and Count with simple condition

Hello everyone,
I'm completly stuck in this problem,wish anyone can give me a solution...(maybe easy)
I have a table below,and want to count [PN]numbers only adapted distinct [PO] counts over 2.
then, created measure below,but doesn't work...(seems Row context is OK,but Grand todal row is incorrect)
How should I correct this measure?


■Table; TEST_

ohnothimagain_1-1721536534866.png

 

■Measure
test91:=var tbl=addcolumns(SUMMARIZE('TEST_','TEST_'[PN]),"@cnt",distinctcount('TEST_'[PO]))
var rst=countx(filter(tbl,[@cnt]>2),[@cnt])
return rst

 

■Result

ohnothimagain_3-1721536769342.png


Thank you for reading.

 (my native language isn't English,sorry for inconvenient)

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@ohnothimagain 

Thanks for testing this, and sorry for my typo! 😅

You're exactly right, the measure should be

test91 :=
VAR PN_PO =
    SUMMARIZE ( 'TEST_', 'TEST_'[PN], 'TEST_'[PO] )
VAR PN_PO_Count =
    GROUPBY ( PN_PO, 'TEST_'[PN], "@PO_Count", SUMX ( CURRENTGROUP (), 1 ) )
VAR PN_Filtered =
    FILTER ( PN_PO_COUNT, [@PO_Count] > 2 )
VAR Result =
    COUNTROWS ( PN_Filtered )
RETURN
    Result

Does that work as intended?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

4 REPLIES 4
OwenAuger
Super User
Super User

@ohnothimagain 

Thanks for testing this, and sorry for my typo! 😅

You're exactly right, the measure should be

test91 :=
VAR PN_PO =
    SUMMARIZE ( 'TEST_', 'TEST_'[PN], 'TEST_'[PO] )
VAR PN_PO_Count =
    GROUPBY ( PN_PO, 'TEST_'[PN], "@PO_Count", SUMX ( CURRENTGROUP (), 1 ) )
VAR PN_Filtered =
    FILTER ( PN_PO_COUNT, [@PO_Count] > 2 )
VAR Result =
    COUNTROWS ( PN_Filtered )
RETURN
    Result

Does that work as intended?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Yes! it worked that I wanted it to be.thank you so much! It was really hard for me to solve by myself!

OwenAuger
Super User
Super User

Hi @ohnothimagain 

I would recommend this:

test91 :=
VAR PN_PO =
    SUMMARIZE ( 'TEST_', 'TEST_'[PN], 'TEST_'[PO] )
VAR PN_PO_Count =
    GROUPBY ( PN_PO, "@PO_Count", SUMX ( CURRENTGROUP (), 1 ) )
VAR PN_Filtered =
    FILTER ( PN_PO_COUNT, [@PO_Count] > 2 )
VAR Result =
    COUNTROWS ( PN_Filtered )
RETURN
    Result

The structure of the measure is similar to that shown in this article:

https://www.sqlbi.com/articles/apply-and-logic-to-multiple-selection-in-dax-slicer/

 

Does this work as intended?

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

OwenAuger
Thank you for responding quickly! (there's noone could in my coutry forums..)
I've copied your DAX and tried just now,Grand Total has changed but sadly something's still wrong..
I want to get value 3 but result is 1,could you give me more advice?

ohnothimagain_0-1721569308049.png
P.S.
I checked in foumulas one by one and figured out suspicious part :
Argument "TEST_PN"  dropped off accidentally..?

GROUPBY ( PN_PO, "@PO_Count", SUMX ( CURRENTGROUP (), 1 ) )


Regards,

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.