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
kiran85
New Member

Need Help - Query to perform summation of a column by selecting distinct rows based on a column

Hi, I am very new to BI. I am trying to get the sum of column X by filtering the distinct rows based on the Column A.

 

My Data looks like below

RecID

BatchID

RecordCount

Remarks

201611280350010172 

092860 

2

ABC

201611280350010172 

092860 

2

llsjd

201611280350010172 

092860 

2

fgfd

201611280350010172 

092860 

2

dfg

201611280350010172 

092860 

2

dfg

201611280350230000

935613 

3

ythe

201611280350230000

935613 

3

shyht

201611280350230000

935613 

3

sdr

201611280350230000

935613 

3

utt

201611280350202000

057808 

1

ghk

201611280350202000

057808 

1

sdew

201611280350202000

057808 

1

dfgj

201611280350202000

057808 

1

sdfr

 

My requirement is to take the distinct rows based on column RecID and sum the values in column RecordCount.

so my expected value is 2+3+1 = 6.

 

Please advise how I can achieve this.

 

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

Hi @kiran85

 

You can create a new summary table using this DAX.  I've assumed your main table is called Table1.

 

You can create SUM based measures on this table that will give you the result of 6

 

Summary Table = SUMMARIZE(
            'Table1',
            Table1[RecID],
            "RecordCount",MAX('Table1'[RecordCount])
            )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

6 REPLIES 6
Phil_Seamark
Employee
Employee

Hi @kiran85

 

You can create a new summary table using this DAX.  I've assumed your main table is called Table1.

 

You can create SUM based measures on this table that will give you the result of 6

 

Summary Table = SUMMARIZE(
            'Table1',
            Table1[RecID],
            "RecordCount",MAX('Table1'[RecordCount])
            )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!


@Phil_Seamark wrote:

Hi @kiran85

 

You can create a new summary table using this DAX.  I've assumed your main table is called Table1.

 

You can create SUM based measures on this table that will give you the result of 6

 

Summary Table = SUMMARIZE(
            'Table1',
            Table1[RecID],
            "RecordCount",MAX('Table1'[RecordCount])
            )

Hi @Phil_Seamark. Thanks for your response. Unfortunately I am receiving an error as "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."

Hi @kiran85

 

Did you create it as a New Table, rather than a New Measure?

 

 

New Table.png

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks Phil

Sean
Community Champion
Community Champion

For Phil solution you have to press the New Table button and then enter the formula! Smiley Happy

 

Here's an alternative using the Query Editor's Group By feature...

 

QE - Group By.gif

 

Both methods will give you the same result! Smiley Happy

Thanks Sean

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.