cancel
Showing results 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.

Skilled Sharer

## How to Summarise VAR table - customer purchase analysis

Hi All,

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

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 =
SUMMARIZE(
FILTER(ALL(Sales), Sales[SaleDate] >= DATE(2021, 01,01) )
,Customers[Cust ID]
,Products[Category ID]
)
,"CatCount" , 1
)

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

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
Community Support

Hi @anandav

You can try the measure as  below.

Measure:

``````_Category Only Customers =
VAR _T =
FILTER (
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.

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.

4 REPLIES 4
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])

Skilled Sharer

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

The PBI file is here.

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

Expected results based on attached PBI file is:

Hope I have explained the requirement clearly.

Community Support

Hi @anandav

You can try the measure as  below.

Measure:

``````_Category Only Customers =
VAR _T =
FILTER (
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.

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.

Skilled Sharer

Thanks a lot. That works.

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

Announcements

#### 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

#### Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

#### Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors