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
cjf4
Regular Visitor

Summing the Results of Grouped Table

What I'm trying to do is create the equivalent of a GROUP BY SQL Statement as a virtual table, and sum the columns of that table.

 

Example:

 

I have data similar to the following table, and I would like to know:

  • The # of Unique Customers with a sale in a given week
  • The # of Unique Customers with multiple sales in a given week

sales_table:

WeekCustomerSale
111111
122221
133331
133331
111111
211111
222221
233331
233331
211111

 

I can accomplish both of these for a given week with the following expressions.

 

UniqueCustomers

calculate(DISTINCTCOUNT(sales_table[Customer]),
	summarize(sales_table, 
		sales_table[Week],
		sales_table[Customer],
		"sales",
		count(sales_table[Customer])))

FrequentCustomers

calculate(DISTINCTCOUNT(sales_table[Customer]),
	filter(summarize(sales_table, 
			sales_table[Week],
			sales_table[Customer],
			"sales",
			count(sales_table[Customer])),
		[Sales]>1)

Both of these work as expected, returning the following for individual weeks:

 

 UniqueFrequent
Week 132
Week 232

 

 

The Problem:

When I want to evaluate this over the 2-week period, I want there to be 6 unqiue sales, and 4 frequent sales. In essence I am looking at each week as self contained, and only care about the number of unique customers in that period. 

 

Instead, when I do the calculations over the two week period, I get 3 unique sales, and 3 frequent sales.

 

Mental solution

 

In my head, I know I just need to sum the results of the intermediate group by table. However, after searching/reading the function defs/experimenting, I haven't been able to do so. Would appreciate any help.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Not sure if it could help. You can create two columns and get the following tables.

 

Unique = CALCULATE(DISTINCTCOUNT(Sheet1[Customer]),ALLEXCEPT(Sheet1,Sheet1[Week]))
Frequent = CALCULATE(SUMX(Sheet1,Sheet1[Sale]),ALLEXCEPT(Sheet1,Sheet1[Week],Sheet1[Customer]))

2018-04-12_14-32-53.png

 

Then in Report, you can add a table with week, unique and frequent fields. Remember to change these 3 values to Don't summarize, and add a filter for Frequent to filter out values that greater than 1.

2018-04-12_14-37-20.png

 

 

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Not sure if it could help. You can create two columns and get the following tables.

 

Unique = CALCULATE(DISTINCTCOUNT(Sheet1[Customer]),ALLEXCEPT(Sheet1,Sheet1[Week]))
Frequent = CALCULATE(SUMX(Sheet1,Sheet1[Sale]),ALLEXCEPT(Sheet1,Sheet1[Week],Sheet1[Customer]))

2018-04-12_14-32-53.png

 

Then in Report, you can add a table with week, unique and frequent fields. Remember to change these 3 values to Don't summarize, and add a filter for Frequent to filter out values that greater than 1.

2018-04-12_14-37-20.png

 

 

 

 

v-chuncz-msft
Community Support
Community Support

@cjf4,

 

You may try a similar way as shown here.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.