Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Arturo24
Frequent Visitor

Sum a column from a filtered table

How do I sum a column form a filtered table that returns the entire value of that filtered column?

 

Example:  If I filter the table below for the laSt two days: days 3 and 4, I want to return the total per dept but also the total for all  depts.  That would be a sum of 21.  Per the documentation the all function must be used on a base table/base column.   That gives me a total of 51 which is the value of the entire table not the filtered table.   What other function is available to sum a filtered column?    Thank you

 

TABLE:

Day;Dept;Units
1;A;4
1;B;3
1;C;8
2;A;5
2;B;7
2;C;3
3;A;1
3;B;0
3;C;2
4;A;6
4;B;7
4;C;5

 

DESIRED RESULT

Dept;Dept_Total;Total
A;7;21
B;7;21
C;7;21

 

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

Try these measures

Measure1 = sum(Data[Units])

Measure2 = calculate([Measure1],allselected(Data[Dept]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

v-jiewu-msft
Community Support
Community Support

Hi @Arturo24 ,

First of all, many thanks to @Ashish_Mathur  for your very quick and effective replies.

Based on my testing, please try the following methods:

1.Create the simple table.

vjiewumsft_0-1715138481757.png

2.Create the new measure to filter the day and return every dept total.

 

Dept total = CALCULATE(SUM('Table'[Units]), FILTER('Table', 'Table'[Day] in {3,4}))

 

 

3.Create the new measure to calculate all dept total.

 

Total = CALCULATE([Dept total], ALL('Table'[Dept]))

 

4.Drag the measures into the table visual.

vjiewumsft_1-1715138541689.png

5.The result is shown below.

vjiewumsft_2-1715138548948.png

Best Regards,

Wisdom Wu

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

6 REPLIES 6
v-jiewu-msft
Community Support
Community Support

Hi @Arturo24 ,

First of all, many thanks to @Ashish_Mathur  for your very quick and effective replies.

Based on my testing, please try the following methods:

1.Create the simple table.

vjiewumsft_0-1715138481757.png

2.Create the new measure to filter the day and return every dept total.

 

Dept total = CALCULATE(SUM('Table'[Units]), FILTER('Table', 'Table'[Day] in {3,4}))

 

 

3.Create the new measure to calculate all dept total.

 

Total = CALCULATE([Dept total], ALL('Table'[Dept]))

 

4.Drag the measures into the table visual.

vjiewumsft_1-1715138541689.png

5.The result is shown below.

vjiewumsft_2-1715138548948.png

Best Regards,

Wisdom Wu

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

Ashish_Mathur
Super User
Super User

Hi,

Try these measures

Measure1 = sum(Data[Units])

Measure2 = calculate([Measure1],allselected(Data[Dept]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
LightSQR
Regular Visitor

What about accomplishing this via a measure (named “DeptTotal”) and a Matrix with a slicer. 

 

I created a table with your data, then created the measure:

DeptTotal = sum('Table'[Units])

 

Then added a slicer with the “Day” field, then came up with this after filtering with the slicer:

LightSQR_0-1715111291049.png

 

(I also put a table with the fields as well just so I could see the data).

 

But by choosing only Day 3 & 4, I get the subtotal for that Dept, but at the bottom get the full filtered total of 21. 

I know I can do it with a slicer.  Sorry should have said that earlier.  Trying to avoid a slicer or a calcualted column.  Should have also said that. 

 

If I do filter the table, what function/method gives me the overall total of 21?   

 

And thank you for taking the time to answer my question.  Much appreciated 🙂

LightSQR
Regular Visitor

Oh wait - just noticed the consolidation in the middle column...  Give me a sec...

 

LightSQR
Regular Visitor

If I'm understanding what you're trying to do correctly, that last column should happen automatically with a standard measure.  So create a new Measure on that table (right-click the table, new measure).  

 

TotalUnits = sum([Units])

 

Add a Table to the report with the Dept, DeptTotal, TotalUnits fields.  

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.