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
ravi_609
Helper I
Helper I

How to calculate conditional customer distinct count?

Hello Friends,
I have attached data table below:

ravi_609_0-1704310532031.png


I need distinct count of CustomerID for "V1-V2" Common Vertical.
Note: If any customer have only "V1" Vertical and "V1-V2-V3"  then it will not count as V1-V2 Common Vertical.

Expected Output:
From dataset image only 2 customer in V1-V2 common group. so measure will give me 2 count.

Please help me out how to write dax for this type of condition.
Thank you once again in advance...!!!

1 ACCEPTED SOLUTION

@ravi_609 

I tested withthe sample youprovided and it worked for me.can you explain how are youtrying to apply this measure?

My table:

Fowmy_0-1704350965696.png


The meaure and the result:

Fowmy_1-1704351005944.png

Porvide more details and screenshots of the error. You may also share dummy data that represent your actual data structure.


 




 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Share data in a format that can be pasted in an MS Excel file.  Sharing an image is useless!!!!


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

@ravi_609 

Try this measure:

COUNTROWS(
	FILTER(
		ADDCOLUMNS(
				DISTINCT(Table06[CustomerID] ),			
				"V" ,
				VAR __A = COUNTROWS( CALCULATETABLE( VALUES( Table06[Vertical] ) , TREATAS( {"V1" ,"V2"} , Table06[Vertical] )) )
				VAR __B = COUNTROWS(CALCULATETABLE( VALUES( Table06[Vertical] ) ) )
				RETURN
				INT(AND(__A=2 ,__B=2))
		),
		[V] = 1
	)
)

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy Thanks for the response but This measure is not working...!!!


I got solution with SQL Server Query:
SELECT CustomerID,COUNT(Verical)
FROM Vertical
GROUP BY CustomerID
HAVING CustomerID not in (Select CustomerID From Vertical where Verical not in ('V1','V2')) and COUNT(Verical) = 2

But I am stuck here that how to use this same logic into measure.

@ravi_609 

I tested withthe sample youprovided and it worked for me.can you explain how are youtrying to apply this measure?

My table:

Fowmy_0-1704350965696.png


The meaure and the result:

Fowmy_1-1704351005944.png

Porvide more details and screenshots of the error. You may also share dummy data that represent your actual data structure.


 




 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Corey_M
Resolver II
Resolver II

 

UniqueIDCount = 
COUNTROWS(
    FILTER(
        SUMMARIZE(
            YourTable,
            YourTable[ID],
            "Verticals", CONCATENATEX(VALUES(YourTable[vertical]), YourTable[vertical], ",")
        ),
        (CONTAINSSTRING([Verticals], "V1") && CONTAINSSTRING([Verticals], "V2")) 
        && NOT CONTAINSSTRING([Verticals], "V3")
    )
)

 

not the most eloquent solution, but this should work

@Corey_M   Thanks for the response but This measure is not working...!!!

I got solution with SQL Server Query:

SELECT CustomerID,COUNT(Verical)
FROM Vertical
GROUP BY CustomerID
HAVING CustomerID not in (Select CustomerID From Vertical where Verical not in ('V1','V2')) and COUNT(Verical) = 2

But I am stuck here that how to use this same logic into measure.

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.