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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
lg01
Helper I
Helper I

Aggregation over facility

See sample below. I have a table with data from different facilities. These facilities have multiple "production tables" and they also have special equipments (water pumps) with a defined gallons capacity. I am trying to calculate the total gallons capacity per facility, based on the capacity of each water pump in the facility. For instance, in the sample below  there is one facility, with two pumps, one has capacity of 5000 gallons the other has a capacity of 3000. So my calculated column "Capacity Per Facility" should report 8000 gal total capacity for the facility. So far I have tried multiple things. The last, shown below, I tried with filters and it gave me a very high number as it was aggregating each line per water_pump_ID.

 

CALCULATE(SUM('Sample Table'[water_pump_capacity (gal)]),ALLEXCEPT('Sample Table','Sample Table'[water_pump_id], 'Sample Table'[facility_id]))

 

The filter though should group by  water pump id and aggregate over the facility. So in this case, it should have aggregated 5000+3000 for the total of 8000 as shown below in the sample

 

facility_idwater_pump_idwater_pump_capacity (gal)Production TableCapacity Per Facility (gal)
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 18000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 28000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 38000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 48000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 58000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 68000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 78000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 88000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 98000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 108000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 118000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 128000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 138000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 148000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 158000
727e274d067b48c3bd4adfddb99b9175f05ef71dc1744fd4ad3264430fd62de83000Table 168000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 178000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 188000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 198000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 208000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 218000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 228000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 238000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 248000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 258000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 268000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 278000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 288000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 298000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 308000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 318000
727e274d067b48c3bd4adfddb99b9175390bb47dbc6f45d3a6e0e60adbc428b25000Table 328000

 

 

Any ideas would be appreciated 

 

 

 

 

1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

Hi @lg01 ,

You can achieve your goal by this DAX calculated column:

Capacity Per Facility (gal) = 
CALCULATE (
    SUMX (
        VALUES ( 'Sample Table'[water_pump_id] ), 
        FIRSTNONBLANK ( 'Sample Table'[water_pump_capacity (gal)], 0 )
    ),
    ALLEXCEPT ( 'Sample Table', 'Sample Table'[facility_id] )
)

 

Now your table will look like this:

Bibiano_Geraldo_0-1737709905418.png

 

Is this post help you? Please consider to:

Accept as Solution!
Give a Kudo
Follow me on Linkedin

View solution in original post

5 REPLIES 5
lg01
Helper I
Helper I

Thank you for all your replies and the effort. Much appreciated. 

Bibiano_Geraldo
Super User
Super User

Hi @lg01 ,

You can achieve your goal by this DAX calculated column:

Capacity Per Facility (gal) = 
CALCULATE (
    SUMX (
        VALUES ( 'Sample Table'[water_pump_id] ), 
        FIRSTNONBLANK ( 'Sample Table'[water_pump_capacity (gal)], 0 )
    ),
    ALLEXCEPT ( 'Sample Table', 'Sample Table'[facility_id] )
)

 

Now your table will look like this:

Bibiano_Geraldo_0-1737709905418.png

 

Is this post help you? Please consider to:

Accept as Solution!
Give a Kudo
Follow me on Linkedin

v-denglli-msft
Community Support
Community Support

Thanks for the reply from DataNinja777 and Ashish_Mathur, please allow me to provide another insight.
Hi @lg01 ,

 

Please try the following DAX.

Capacity Per Facility (gal) = 
VAR _tb =
    SUMMARIZECOLUMNS (
        'Table'[facility_id],
        'Table'[water_pump_id],
        'Table'[water_pump_capacity (gal)]
    )
RETURN
    SUMX ( _tb, [water_pump_capacity (gal)] )

 The SUMMARIZECOLUMNS function creates a virtual table grouped by water_pump_id.
Then use the SUMX function to aggregate water_pump_capacity.

vdengllimsft_1-1737683469036.png

 

The final result is as follows. Hopefully it will meet your needs.

vdengllimsft_0-1737683121476.png

 

Please see the attahced pbix for reference.


Best Regards,
Dengliang Li

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,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1737678238949.png

 


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

Hi @lg01 ,

 

To calculate the total water pump capacity per facility, you can use a DAX formula to either create a calculated column or a measure. A calculated column will display the total capacity per facility for each row in your table, while a measure dynamically calculates the value in visuals without adding to the data model size.

For the calculated column, you can use the following DAX formula:

Capacity Per Facility (gal) = 
CALCULATE(
    SUM('Sample Table'[water_pump_capacity (gal)]),
    ALLEXCEPT('Sample Table', 'Sample Table'[facility_id])
)

This formula sums up the water pump capacities for all rows grouped by the facility_id. The ALLEXCEPT function ensures that only the facility_id filter is retained, providing the correct aggregation of pump capacities within each facility.

Alternatively, if you prefer a dynamic approach using a measure, the DAX formula can be written as:

Total Facility Capacity = 
SUMX(
    VALUES('Sample Table'[water_pump_id]),
    CALCULATE(
        MAX('Sample Table'[water_pump_capacity (gal)])
    )
)

This measure dynamically calculates the total capacity by iterating over each unique water pump within the facility using the VALUES function, ensuring no duplication of pump capacities. The MAX function ensures that the correct capacity for each pump is considered, and SUMX aggregates these values for the entire facility.

Using either approach, the total capacity for the facility with facility_id = 727e274d067b48c3bd4adfddb99b9175 will correctly return 8000 gallons (5000 + 3000). Let me know if further clarification is needed!

 

Best regards,

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.