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
Saxon10
Post Prodigy
Post Prodigy

Distinct count based on the two columns

 

This is sales data. If same item has dispatched multiple country then result is Yes and if not then No.

 

I search in Power BI forum and I can't found any similer thread so could you please advise.

 

ItemArea CodeDesired Result
123IndYes
123UkYes
123usYes
123AusYes
124IndNo
124IndNo
124IndNo
125IndYes
125UkYes
126UsNo
127AusNo

 

Saxon10_0-1622935154970.png

 

3 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

@Saxon10 

Try it like this

Multiple Areas = 
VAR _Areas =
    CALCULATETABLE (
        SUMMARIZE ( 'Table', 'Table'[Area Code], 'Table'[Item] ),
        REMOVEFILTERS ( 'Table'[Area Code] )
    )
VAR _Result =
    COUNTROWS ( _Areas )
RETURN
    IF ( _Result > 1, "Yes", "No" )

 

jdbuchanan71_0-1622939285098.png

You could also use this as a measure instead of a calculated column.

 

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

=if(calculate(distinctcount(Data[Area code]),filter(Data,Data[Item]=earlier(Data[Item])))>1,"Yes","No")

Hope this helps.


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

View solution in original post

Jihwan_Kim
Super User
Super User

Hi, @Saxon10 

Please check the below for creating a new measure.

 

Picture1.png

 

Disinct Count Measure =
VAR currentareacode =
MAX ( 'Table'[Area Code] )
VAR currentitem =
MAX ( 'Table'[Item] )
VAR filtercondition =
FILTER ( ALL ( 'Table' ), 'Table'[Area Code] <> currentareacode )
VAR tablewithoutcurrentareacode =
SUMMARIZE ( filtercondition, 'Table'[Item] )
VAR result =
IF ( currentitem IN tablewithoutcurrentareacode, "Yes", "No" )
RETURN
IF ( ISFILTERED ( 'Table'[Item] ), result )

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi, @Saxon10 

Please check the below for creating a new measure.

 

Picture1.png

 

Disinct Count Measure =
VAR currentareacode =
MAX ( 'Table'[Area Code] )
VAR currentitem =
MAX ( 'Table'[Item] )
VAR filtercondition =
FILTER ( ALL ( 'Table' ), 'Table'[Area Code] <> currentareacode )
VAR tablewithoutcurrentareacode =
SUMMARIZE ( filtercondition, 'Table'[Item] )
VAR result =
IF ( currentitem IN tablewithoutcurrentareacode, "Yes", "No" )
RETURN
IF ( ISFILTERED ( 'Table'[Item] ), result )

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

=if(calculate(distinctcount(Data[Area code]),filter(Data,Data[Item]=earlier(Data[Item])))>1,"Yes","No")

Hope this helps.


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

@Saxon10 

Try it like this

Multiple Areas = 
VAR _Areas =
    CALCULATETABLE (
        SUMMARIZE ( 'Table', 'Table'[Area Code], 'Table'[Item] ),
        REMOVEFILTERS ( 'Table'[Area Code] )
    )
VAR _Result =
    COUNTROWS ( _Areas )
RETURN
    IF ( _Result > 1, "Yes", "No" )

 

jdbuchanan71_0-1622939285098.png

You could also use this as a measure instead of a calculated column.

 

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.