Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
GaborBenyei
Frequent Visitor

Groups based on measure considering date slicer

Hello, I would like to count the number of customers depending on the number of shops they transacted in. Everything should be calculated considering a date slicer. The Summary table is the expected result. Any help is much appriaciated.
Raw data:

TransactionDateCustomerIdShopIdAmount
01/01/2025Customer1Shop150
01/01/2025Customer1Shop240
01/01/2025Customer1Shop360
01/01/2025Customer2Shop112
01/01/2025Customer2Shop520
01/01/2025Customer2Shop630
01/01/2025Customer2Shop725
01/01/2025Customer3Shop826
01/01/2025Customer4Shop227
02/01/2025Customer1Shop150
02/01/2025Customer2Shop520
02/01/2025Customer3Shop826
02/01/2025Customer4Shop227
02/01/2025Customer5Shop328
02/01/2025Customer5Shop429
03/01/2025Customer1Shop150
03/01/2025Customer2Shop520
03/01/2025Customer3Shop826
03/01/2025Customer4Shop227
04/01/2025Customer1Shop150
04/01/2025Customer1Shop240
04/01/2025Customer2Shop520
04/01/2025Customer2Shop620
04/01/2025Customer3Shop826
04/01/2025Customer4Shop227

 

Sample1:

TransactionDate: 01/01/2025-04/01/2025 
CustomerIdCount of Shops
Customer13
Customer24
Customer31
Customer41
Customer52

 

Summary1:

Count of ShopsCount of Customers
12
21
3 or more2

 

Sample2

TransactionDate: 02/01/2025-04/01/2025 
CustomerIdCount of Shops
Customer12
Customer22
Customer31
Customer41
Customer52

 

Summary2:

Count of ShopsCount of Customers
12
23
3 or more0
1 ACCEPTED SOLUTION
v-ssriganesh
Community Support
Community Support

Hello @GaborBenyei,
Thank you for reaching out to the Microsoft Fabric Forum Community.

I’ve reproduced your scenario using sample data matching your raw data structure and achieved the expected output for both date ranges (01/01/2025 - 04/01/2025 and 02/01/2025 - 04/01/2025). I’m attaching a .pbix file for your reference, which includes the solution implemented with your sample data. Below are the steps I followed to create it:

  • I loaded your raw data into a table named Transactions in Power BI and checked TransactionDate is formatted as a Date type.

  • Added the following DAX measures to the Transactions table:
ShopCountPerCustomer =

DISTINCTCOUNT(Transactions[ShopId])
CustomersWith1Shop =

CALCULATE(

    DISTINCTCOUNT(Transactions[CustomerId]),

    FILTER(

        ADDCOLUMNS(VALUES(Transactions[CustomerId]), "ShopCount", [ShopCountPerCustomer]),

        [ShopCount] = 1

    )

)
CustomersWith2Shops =

CALCULATE(

    DISTINCTCOUNT(Transactions[CustomerId]),

    FILTER(

        ADDCOLUMNS(VALUES(Transactions[CustomerId]), "ShopCount", [ShopCountPerCustomer]),

        [ShopCount] = 2

    )

)
CustomersWith3OrMoreShops =

CALCULATE(

    DISTINCTCOUNT(Transactions[CustomerId]),

    FILTER(

        ADDCOLUMNS(VALUES(Transactions[CustomerId]), "ShopCount", [ShopCountPerCustomer]),

        [ShopCount] >= 3

    )

)
CustomerCountByShopGroup =

SWITCH(

    SELECTEDVALUE(SummaryCategories[Count of Shops]),

    "1", [CustomersWith1Shop],

    "2", [CustomersWith2Shops],

    "3 or more", [CustomersWith3OrMoreShops],

    BLANK()

)
  • Created a disconnected table named SummaryCategories using Enter Data with one column Count of Shops and these values:
      • "1"
      • "2"
      • "3 or more"
  • Added a Slicer using Transactions[TransactionDate] set to “Between” mode.
  • Added a Table visual with CustomerId and ShopCountPerCustomer to verify per-customer shop counts.
  • Added a Table visual with SummaryCategories[Count of Shops] and CustomerCountByShopGroup for the summary output.

The .pbix file attached demonstrates this working solution with your sample data. You can adjust the slicer to test different date ranges, and the measures will dynamically update to reflect the number of customers grouped by shop counts.

If this information is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

View solution in original post

6 REPLIES 6
v-ssriganesh
Community Support
Community Support

Hello @GaborBenyei,
Thank you for reaching out to the Microsoft Fabric Forum Community.

I’ve reproduced your scenario using sample data matching your raw data structure and achieved the expected output for both date ranges (01/01/2025 - 04/01/2025 and 02/01/2025 - 04/01/2025). I’m attaching a .pbix file for your reference, which includes the solution implemented with your sample data. Below are the steps I followed to create it:

  • I loaded your raw data into a table named Transactions in Power BI and checked TransactionDate is formatted as a Date type.

  • Added the following DAX measures to the Transactions table:
ShopCountPerCustomer =

DISTINCTCOUNT(Transactions[ShopId])
CustomersWith1Shop =

CALCULATE(

    DISTINCTCOUNT(Transactions[CustomerId]),

    FILTER(

        ADDCOLUMNS(VALUES(Transactions[CustomerId]), "ShopCount", [ShopCountPerCustomer]),

        [ShopCount] = 1

    )

)
CustomersWith2Shops =

CALCULATE(

    DISTINCTCOUNT(Transactions[CustomerId]),

    FILTER(

        ADDCOLUMNS(VALUES(Transactions[CustomerId]), "ShopCount", [ShopCountPerCustomer]),

        [ShopCount] = 2

    )

)
CustomersWith3OrMoreShops =

CALCULATE(

    DISTINCTCOUNT(Transactions[CustomerId]),

    FILTER(

        ADDCOLUMNS(VALUES(Transactions[CustomerId]), "ShopCount", [ShopCountPerCustomer]),

        [ShopCount] >= 3

    )

)
CustomerCountByShopGroup =

SWITCH(

    SELECTEDVALUE(SummaryCategories[Count of Shops]),

    "1", [CustomersWith1Shop],

    "2", [CustomersWith2Shops],

    "3 or more", [CustomersWith3OrMoreShops],

    BLANK()

)
  • Created a disconnected table named SummaryCategories using Enter Data with one column Count of Shops and these values:
      • "1"
      • "2"
      • "3 or more"
  • Added a Slicer using Transactions[TransactionDate] set to “Between” mode.
  • Added a Table visual with CustomerId and ShopCountPerCustomer to verify per-customer shop counts.
  • Added a Table visual with SummaryCategories[Count of Shops] and CustomerCountByShopGroup for the summary output.

The .pbix file attached demonstrates this working solution with your sample data. You can adjust the slicer to test different date ranges, and the measures will dynamically update to reflect the number of customers grouped by shop counts.

If this information is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

Hi @v-ssriganesh , Thank you for your solution, it works as expected. The only issue is when I try to use this  in my original database, that contains millions of rows, it takes ages to calculate and got this error message if the selected period is longer. Any idea for this? Maybe a different approach? I used calculated table for a similar task where I did not needed to use date slicers, and that performed better. But unfortunatelly calculated tables does not consider the selected period dinamically. Aything similar to that?

GaborBenyei_0-1743517145971.png

 

rajendraongole1
Super User
Super User

Hi @GaborBenyei  - you can create a measure to count the distinct number of shops each customer transacted in within the selected date range

 

 

CountShops =
CALCULATE(
DISTINCTCOUNT(Transactions[ShopId]),
ALLEXCEPT(Transactions, Transactions[CustomerId])
)

 

Create a Measure for Summary Table

CustomerCountByShopGroup =
VAR SummaryTable =
ADDCOLUMNS(
SUMMARIZE(Transactions, Transactions[CustomerId]),
"ShopCount", [CountShops]
)
VAR Count1 = COUNTROWS(FILTER(SummaryTable, [ShopCount] = 1))
VAR Count2 = COUNTROWS(FILTER(SummaryTable, [ShopCount] = 2))
VAR Count3OrMore = COUNTROWS(FILTER(SummaryTable, [ShopCount] >= 3))

RETURN
UNION(
ROW("Count of Shops", "1", "Count of Customers", Count1),
ROW("Count of Shops", "2", "Count of Customers", Count2),
ROW("Count of Shops", "3 or more", "Count of Customers", Count3OrMore)
)

 

Now, you can use CustomerId and CountShops in a table to see individual customer counts.

Use CustomerCountByShopGroup in another table to display the summarized count of customers by shop count categories.





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

Proud to be a Super User!





Hi @rajendraongole1 , thanks for trying to help, however I got this error message:

 

GaborBenyei_0-1743345291476.png

 

 

Hi @GaborBenyei - can you please try the modified one.

 

CustomerCountByShopGroup =
VAR SummaryTable =
ADDCOLUMNS(
SUMMARIZE(Transactions, Transactions[CustomerId]),
"ShopCount", DISTINCTCOUNT(Transactions[ShopId])
)

VAR Count1 = COUNTROWS(FILTER(SummaryTable, [ShopCount] = 1))
VAR Count2 = COUNTROWS(FILTER(SummaryTable, [ShopCount] = 2))
VAR Count3OrMore = COUNTROWS(FILTER(SummaryTable, [ShopCount] >= 3))

RETURN
UNION(
ROW("Count of Shops", "1", "Count of Customers", Count1),
ROW("Count of Shops", "2", "Count of Customers", Count2),
ROW("Count of Shops", "3 or more", "Count of Customers", Count3OrMore)
)

 

Hope this helps





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

Proud to be a Super User!





Hi @rajendraongole1 , Unfortunately I got the same error message.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors