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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jayjay0306
Helper III
Helper III

Flag doublets in a calculated (SUMMARIZE) table?

Hi people,

I need your help:

I have made a calculated table in Power BI Desktop

Table = SUMMARIZE('Sales','Sales'[CUSTOMER_KEY],Customer[Customer No],
				"Customer",NOT(ISBLANK(max(Customer[Customer No]))),
				"count",DISTINCTCOUNT('Sales'[CUSTOMER_KEY]),
				"Number of buying customers",DISTINCTCOUNT(Customer[Customer No]))

In this table I get doublet "Customer No" due to multiple "Customer keys"

Doublets.PNG

No, my question is: How do I make a DAX script, which basically flags the doublets with the lowest Customer key?

I haver tried variuous things with no succes. One reason is I have a hard time trying to reference to another column in a calculated table?

What I need is somthing like this:

Doublets2.PNG

(or maybe "TRUE/FALSE", "1/empty".....anything will do)

Any ideas or leads will be greatly appreciated?

thanks.

Br,

JJ

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @jayjay0306 ,

Here are the steps you can follow:

1. Create calculated column.

Number of customers =
var _count=
COUNTX(FILTER(ALL(Sales),'Sales'[Customer_No]=EARLIER('Sales'[Customer_No])),[Customer_No])
var _max=
MAXX(FILTER(ALL('Sales'),'Sales'[Customer_No]=EARLIER('Sales'[Customer_No])),[CUSTOMER_KEY])
return
IF(
    'Sales'[CUSTOMER_KEY]=_max&&_count>1,1,
    IF(
        _count=1,    CALCULATE(DISTINCTCOUNT(Sales[Customer_No]),FILTER(ALL('Sales'),'Sales'[Customer_No]=EARLIER('Sales'[Customer_No]))),0))

2. Result:

vyangliumsft_0-1663058864110.png

 

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

5 REPLIES 5
Anonymous
Not applicable

Hi  @jayjay0306 ,

Here are the steps you can follow:

1. Create calculated column.

Number of customers =
var _count=
COUNTX(FILTER(ALL(Sales),'Sales'[Customer_No]=EARLIER('Sales'[Customer_No])),[Customer_No])
var _max=
MAXX(FILTER(ALL('Sales'),'Sales'[Customer_No]=EARLIER('Sales'[Customer_No])),[CUSTOMER_KEY])
return
IF(
    'Sales'[CUSTOMER_KEY]=_max&&_count>1,1,
    IF(
        _count=1,    CALCULATE(DISTINCTCOUNT(Sales[Customer_No]),FILTER(ALL('Sales'),'Sales'[Customer_No]=EARLIER('Sales'[Customer_No]))),0))

2. Result:

vyangliumsft_0-1663058864110.png

 

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

Hi Liu Yang,

 

bloody brilliant! it works. Thanks 🙂

 

Br,

JayJay0306

Anonymous
Not applicable

Hi  @jayjay0306 ,

 

Here are the steps you can follow:

1. Create calculated column.

Number of customers =
var _count=
COUNTX(FILTER(ALL(Sales),'Sales'[Customer_No]=EARLIER('Sales'[Customer_No])),[Customer_No])
var _min=
MINX(FILTER(ALL('Sales'),'Sales'[Customer_No]=EARLIER('Sales'[Customer_No])),[CUSTOMER_KEY])
return
IF(
    'Sales'[CUSTOMER_KEY]=_min,_count,  CALCULATE(DISTINCTCOUNT(Sales[Customer_No]),FILTER(ALL('Sales'),'Sales'[Customer_No]=EARLIER('Sales'[Customer_No]))))

2. Result:

vyangliumsft_0-1663044561859.png

 

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

thanks Liu Yang,

I'm getting closer, but I have found out there are customers who appears more than twice, and then I get this:

Capture2.PNG

Basically, what I need is this, for customers who appears more than once:

Capture3.PNG

along with the customers who only appears once (as expected):

example:

Capture4.PNG

 

in that way, I can simply SUM([Number of Customers]) and get the "number of customers", which is the goal.

 

thanks. Any solution is greatly appreciated.

br,

JayJay0306

 

 

tamerj1
Super User
Super User

Hi @jayjay0306 

you can creat a new calculated column in table as

Flag =
IF ( countrows ( CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Customer Number] )))> 1, 1,0 )

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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.