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

Create a measure to sum unique values from another column and group by ID

I am working with data from a video chat app. Some entries are duplicated because they correspond to different events within a single call. The data looks as follows:

account_idcall_ideventduration
42abcdefCallStarted22
42abcdefCallEnded22
45abcdefCallStarted21
45abcdefCallEnded21
99ghijklmCallReceived13
99ghijklmCallAnswered13
99ghijklmCallEnded13
13nopqrsCallConnected39
13tuvwxyCallAccepted15
13tuvwxyCallEnded15

I need to get the sum of `duration` for each `account_id` in the table. However, I need to account for only one row per `account_id` and `call_id` combination.

I would like to get the following result from the sample data I posted above:

account_idsum_duration
42

22

4521
9913
1344

How can I achieve this?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous Try this:

Measure = 
  VAR __Table = 
    GROUPBY(
      'Table',
      [account_id],
      [call_id],
      "__Sum",SUMX(CURRENTGROUP(),[duration])
    )
  VAR __Result = SUMX(__Table,[__Sum])
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@Anonymous Try this:

Measure = 
  VAR __Table = 
    GROUPBY(
      'Table',
      [account_id],
      [call_id],
      "__Sum",SUMX(CURRENTGROUP(),[duration])
    )
  VAR __Result = SUMX(__Table,[__Sum])
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

In the end, I opted for importing the data using `ROW_NUMBER()` directly in the SQL query to only sum the first row per combination.
However, your solution works too, so thank you!

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.