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

Powerbi group by sum measure in table visual

Hi all,

I require this in table visual,

id         Col 2   col3   col4   sum

1111      1                              3

1111       2                            should not display anything

22222     5                             9

22222     4                             should not display anything 

I used the following measure

Calculate(sum(col2) ,allexcept(id)))

Its showing as below

id         Col 2   col3   col4   sum

1111      1                              3

1111       2                            3

22222     5                             9

22222     4                             9

Pls help me in resolving this

2 ACCEPTED SOLUTIONS

Ok, to be able to show all rows, you are going to need to add an index column in Power Query.

I've also created a dimension table for name, address and ID. The mopdel looks like this:

model.png

 

You can then use this measure:

Summary Salary =
VAR _SalaryByID =
    CALCULATE ( SUM ( fTable[Salary paid] ), ALLEXCEPT ( fTable, 'Dim Name'[Id] ) )
VAR _MinIndex =
    CALCULATE ( MIN ( fTable[Index] ), ALLEXCEPT ( fTable, 'Dim Name'[Id] ) )
RETURN
    IF ( MAX ( fTable[Index] ) = _MinIndex, _SalaryByID )

Add the fields & the measure to a table visual, right click on the Index field and select "Show items with no data:

items.png

 

Sample PBIX file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

It depends what you want to "group" the values by. If it's only ID (which is the same for name and mobile number) then all you need is 

ALLEXCEPT(fTable, 'Dim Name'[Id])
If you need to "group" by more columns, you need to include them in the ALLEXCEPT

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

11 REPLIES 11
PaulDBrown
Community Champion
Community Champion

What does the original data look like?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hi,

I can provide only sample data as client data is confidential from my end.

Sample data would be perfect





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thansks for the sample. Just to confirm, one of the IDs has more than 1 mobile number, correct? Also, it appears you want to show all the rows, but only the aggregated Salary per ID  on one row: is there any particular criteria to allot the aggragated salary to a row?

detail.png

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Yes we need to display all rows from sample with one aggregated sum.Ignore mistake in mobile number

Ok, to be able to show all rows, you are going to need to add an index column in Power Query.

I've also created a dimension table for name, address and ID. The mopdel looks like this:

model.png

 

You can then use this measure:

Summary Salary =
VAR _SalaryByID =
    CALCULATE ( SUM ( fTable[Salary paid] ), ALLEXCEPT ( fTable, 'Dim Name'[Id] ) )
VAR _MinIndex =
    CALCULATE ( MIN ( fTable[Index] ), ALLEXCEPT ( fTable, 'Dim Name'[Id] ) )
RETURN
    IF ( MAX ( fTable[Index] ) = _MinIndex, _SalaryByID )

Add the fields & the measure to a table visual, right click on the Index field and select "Show items with no data:

items.png

 

Sample PBIX file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hi i got your approach,but the problem here my data contains 120 columns,Do we need to summarise repating data or all 120 columns except id

Thanks in advance

If the other columns are values, then yes, you will need a measure for each





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






No i mean that if we are having 120 columns in sample table.Do we need to summarise with  120 columns because i am not getting desired output when summarised with few columns? 

It depends what you want to "group" the values by. If it's only ID (which is the same for name and mobile number) then all you need is 

ALLEXCEPT(fTable, 'Dim Name'[Id])
If you need to "group" by more columns, you need to include them in the ALLEXCEPT

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






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.