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
Ani26
Helper III
Helper III

Count of a customer subcribed to 2 products

Hi Team,

May be this is a very simple question but I am totally lost doing it and finally would require your help in achieving the result. I have a sample data as below.

CustomerProduct
AnshWater
PradsFire
KapilFire
KapilWater
SamFire
MichaelFire
AdnamWater
SikoFire
TedFire
AcquaWater
EliesWater
BoardFire
BoardWater

 

The requirement is I need to find the distinct count of Customers who have subscribed to both Fire and Water together. So from the above example I should be getting Raj and Board as the 2 distinct customers who haved subscribed to both Fire and Water together.

 

Request you to kindly assist me with the same.

Please let me know if any additional information required.

 

Thanks,

Ani

4 REPLIES 4
speedramps
Super User
Super User

Hi Ani

 

Please conisder this solution and leave kudos


NO sales = COUNTROWS(Sales)                                                         -- number of sales rows
NO fire = CALCULATE(Sales[NO sales],Sales[Product]="Fire")            -- number of fire sales rows
NO water = CALCULATE(Sales[NO sales],Sales[Product]="Water")    -- number of water sales rows
NO customer with both = 
-- number of customers with both fire and water sales rows
CALCULATE(DISTINCTCOUNT(Sales[Customer]),
FILTER(Sales,[NO fire] > 0 && [NO water] > 0)
)

camargos88
Community Champion
Community Champion

Hi @Ani26 ,

 

Try this measure:

 

Measure =
CALCULATE(DISTINCTCOUNT('Table'[Customer]),
INTERSECT(
SELECTCOLUMNS(FILTER('Table', 'Table'[Product] = "Fire"), "Customer", 'Table'[Customer]),
SELECTCOLUMNS(FILTER('Table', 'Table'[Product] = "Water"), "Customer", 'Table'[Customer])
)
)
 
or
 
Measure =
COUNTROWS(
FILTER(
SUMMARIZE('Table', 'Table'[Customer], "QtProduct", CALCULATE(DISTINCTCOUNT('Table'[Product]), FILTER('Table', 'Table'[Product] = "Fire" || 'Table'[Product] = "Water"))),
[QtProduct] = 2)
)


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



edhans
Super User
Super User

This should do it.

 

 

 

Count Customers = 
COUNTROWS(
    FILTER(
        ADDCOLUMNS(
            SUMMARIZE(
                Customers,
                Customers[Customer]
            ),
            "Combined Products", CALCULATE(
                CONCATENATEX(
                    Customers,
                    Customers[Product]
                )
            )
        ),
        [Combined Products] = "WaterFire"
        	|| [Combined Products] = "FireWater"
    )
)

 

 

EDIT: I did that really quick. I prefer things to be a bit more readable and modular. So I like the below better, but they both produce 2 as the answer.

 

Count Customers =
VAR TempTable =
    ADDCOLUMNS(
        SUMMARIZE(
            Customers,
            Customers[Customer]
        ),
        "Combined Products", CALCULATE(
            CONCATENATEX(
                Customers,
                Customers[Product]
            )
        )
    )
VAR JustFireWater =
    FILTER(
        TempTable,
        [Combined Products] = "WaterFire"
            || [Combined Products] = "FireWater"
    )
VAR FinalRowCount =
    COUNTROWS( JustFireWater )
RETURN
    FinalRowCount

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thanks @edhans  and @camargos88 
Both the solutions helped me get to my answer. Thanks a lot 🙂 

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.