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
Anonymous
Not applicable

Count of the number of instances making up a sum

I am trying to create a column that shows how many items make up a sum.  In Excel I might use a PivotTable on a PivotTable to achieve this:

image.png

 

So the 3rd table shows that the metric for two UIDs sums to 1, one UID to 2 and two UIDs to 3

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create a calculated column

sum = CALCULATE(COUNT('Table'[uid]),ALLEXCEPT('Table','Table'[uid]))

Create a measure

uid count = CALCULATE(DISTINCTCOUNT('Table'[uid]),ALLEXCEPT('Table','Table'[sum]))

Capture16.JPG

 

Best Regards

Maggie

Community Support Team _ Maggie Li

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

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create a calculated column

sum = CALCULATE(COUNT('Table'[uid]),ALLEXCEPT('Table','Table'[uid]))

Create a measure

uid count = CALCULATE(DISTINCTCOUNT('Table'[uid]),ALLEXCEPT('Table','Table'[sum]))

Capture16.JPG

 

Best Regards

Maggie

Community Support Team _ Maggie Li

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

JosefPrakljacic
Solution Sage
Solution Sage

Hey @Anonymous 

 

 

Does this help? 

 

If not would you mind to provide us with copyable sample data or a sample file?

 

If this post was helpful may I ask you to mark it as solution and give it some kudos?

Have a nice day!

BR,
Josef

Anonymous
Not applicable

Hi Josef, 

It doesn't, in your example the UID counts should equal 1 for all because each Metric value has one UID associated with it.  Unfortunately I can't use file sharing services, but this is how the new table or column would look:

image.png

 

The equivalent SQL syntax would be:

WITH A AS (
  SELECT 
    ID,
    SUM(METRIC) 'SUM'
  FROM MERGED_DF2
  GROUP BY ID
)
SELECT
 SUM,
 COUNT(*) 'UIDS WITH SUM'
FROM A
GROUP BY SUM

 

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.