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
anandav
Skilled Sharer
Skilled Sharer

How to Summarise VAR table - customer purchase analysis

Hi All,

I have a standard star schema of Sales, Products and Customers

anandav_2-1627880667019.png

 

I wanted to count how many customers have bought products ONLY in ONE category for the given period.

e.g. C1 and C2

 

I have a measure

1. Summarize sales by Customer and Category ID

VAR T1 = 
ADDCOLUMNS(
            SUMMARIZE(
                FILTER(ALL(Sales), Sales[SaleDate] >= DATE(2021, 01,01) )
                ,Customers[Cust ID]
                ,Products[Category ID]
            )
            ,"CatCount" , 1
        )

anandav_3-1627881096303.png

 

Now I wanted another VAR table T2 that will add CatCount by Customer 

anandav_4-1627881250906.png

 

My thinking is by filtering T2 where CategoryID = "PC1"  && CatCount = 1 should give me customers who have ONLY bought in Product Category PC1

 

Any suggestion how I can do this please?

 

 

1 ACCEPTED SOLUTION

Hi @anandav 

You can try the measure as  below.

Measure:

 

_Category Only Customers =
VAR _T =
    FILTER (
        ADDCOLUMNS (
            Sales,
            "COUNT_",
                CALCULATE (
                    DISTINCTCOUNT ( Products[Product Category] ),
                    FILTER ( ALL ( Sales ), Sales[Customer] = EARLIER ( Sales[Customer] ) )
                )
        ),
        [COUNT_] = 1
            && [SaleDate] >= DATE ( 2021, 01, 01 )
    )
VAR _T2 =
    SUMMARIZE ( _T, [Customer] )
RETURN
    COUNTX ( _T2, [Customer] )

 

Result is as below.

 1.png

 

Best Regards,

Rico Zhou

 

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

4 REPLIES 4
amitchandak
Super User
Super User

@anandav , Try a measure like

 

countx(filter(
SUMMARIZE(
FILTER(ALL(Sales), Sales[SaleDate] >= DATE(2021, 01,01) )
,Customers[Cust ID]
, "_Count", distinctCOUNT(Products[Category ID])
)
,[_Count] =1
), [Cust ID])

@amitchandak ,

Thank you for the reply.

Using the above DAX I am getting the same value for all Product Categories.

The PBI file is here.

 

anandav_0-1627990311122.png

 

What I need is the Categories where customers have ONLY purchased in that category.

 

Expected results based on attached PBI file is:

anandav_1-1627990687520.png

 

Hope I have explained the requirement clearly.

 

 

Hi @anandav 

You can try the measure as  below.

Measure:

 

_Category Only Customers =
VAR _T =
    FILTER (
        ADDCOLUMNS (
            Sales,
            "COUNT_",
                CALCULATE (
                    DISTINCTCOUNT ( Products[Product Category] ),
                    FILTER ( ALL ( Sales ), Sales[Customer] = EARLIER ( Sales[Customer] ) )
                )
        ),
        [COUNT_] = 1
            && [SaleDate] >= DATE ( 2021, 01, 01 )
    )
VAR _T2 =
    SUMMARIZE ( _T, [Customer] )
RETURN
    COUNTX ( _T2, [Customer] )

 

Result is as below.

 1.png

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

@v-rzhou-msft 

Thanks a lot. That works.

Really appreciate your help. 

 

Ps. Sorryfor the late reply - off work due to some issues.

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.