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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
cheid
Frequent Visitor

Sum average using summarize function

I was given the below table that I mapped to a line item table by the routeid column using the related function. Because I am using a line item table there are multiple lines of counts and cost per order.  

 

cheid_0-1766767803328.png

 

These counts and cost need to rollup to division level that is mapped back to the invoice table.  To rollup everthing to the division level in the stops table I used the below DAX logic.  The problem I am having is that I need to sum the average of each average.  Is there away to sum the average using summarize?    I tried using SUMX, but it's not working.  

 

Longhaul Rates =
 FILTER(
     SUMMARIZE(        
        STOPS,
        STOPS[Division],
        STOPS[Start of Week],
        STOPS[RouteID],
        "AVG TRC CNT",AVERAGE(STOPS[Longhaul Tractor Cnt]),
        "AVG TRL CNT",AVERAGE(STOPS[Longhaul Trailer Cnt]),
        "AVG TRC COST",AVERAGE(STOPS[Longhaul Tractor Cost]),
        "AVG TRL COST",AVERAGE(STOPS[Longhaul Trailer Cost])
     ),
     NOT(ISBLANK([AVG TRC CNT]
     )
     )
)
 
 
This is what I want the final table to look like.
cheid_1-1766768613174.png

 

1 ACCEPTED SOLUTION
krishnakanth240
Responsive Resident
Responsive Resident

Hi @cheid 

 

Build the Route-level averages (virtual table)
VAR RouteAvgTable =
SUMMARIZE(
STOPS,
STOPS[Division],
STOPS[Start of Week],
STOPS[RouteID],
"Avg_Tractor_Cnt", AVERAGE(STOPS[Longhaul Tractor Cnt]),
"Avg_Trailer_Cnt", AVERAGE(STOPS[Longhaul Trailer Cnt]),
"Avg_Tractor_Cost", AVERAGE(STOPS[Longhaul Tractor Cost]),
"Avg_Trailer_Cost", AVERAGE(STOPS[Longhaul Trailer Cost])
)


Sum those averages to Division level
Allocated Tractor Count =
SUMX(
RouteAvgTable,
[Avg_Tractor_Cnt]
)

 

Allocated Trailer Count =
SUMX(
RouteAvgTable,
[Avg_Trailer_Cnt]
)

 

Allocated Tractor Cost =
SUMX(
RouteAvgTable,
[Avg_Tractor_Cost]
)

 

Allocated Trailer Cost =
SUMX(
RouteAvgTable,
[Avg_Trailer_Cost]
)

 

If this doesn't works out, then please share the sample data with the required logic and outout. Thank You!

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @cheid 

Use CALCUALTE to convert row context into filter context for  each aggregation

FILTER (
    ADDCOLUMNS (
        SUMMARIZE (
            STOPS,
            STOPS[Division],
            STOPS[Start of Week],
            STOPS[RouteID]
        ),
        "AVG TRC CNT",  CALCULATE ( AVERAGE ( STOPS[Longhaul Tractor Cnt] ) ),
        "AVG TRL CNT",  CALCULATE ( AVERAGE ( STOPS[Longhaul Trailer Cnt] ) ),
        "AVG TRC COST", CALCULATE ( AVERAGE ( STOPS[Longhaul Tractor Cost] ) ),
        "AVG TRL COST", CALCULATE ( AVERAGE ( STOPS[Longhaul Trailer Cost] ) )
    ),
    NOT ( ISBLANK ( [AVG TRC CNT] ) )
)

It is uncler though which column/virtual column (calcualated columns inside the table) you want to be summed but assuming you want it for "AVT TRC CNT", that would be 

SUMX (
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                STOPS,
                STOPS[Division],
                STOPS[Start of Week],
                STOPS[RouteID]
            ),
            "AVG TRC CNT",  CALCULATE ( AVERAGE ( STOPS[Longhaul Tractor Cnt] ) ),
            "AVG TRL CNT",  CALCULATE ( AVERAGE ( STOPS[Longhaul Trailer Cnt] ) ),
            "AVG TRC COST", CALCULATE ( AVERAGE ( STOPS[Longhaul Tractor Cost] ) ),
            "AVG TRL COST", CALCULATE ( AVERAGE ( STOPS[Longhaul Trailer Cost] ) )
        ),
        NOT ( ISBLANK ( [AVG TRC CNT] ) )
    ),
    [AVG TRC CNT]
)




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
FBergamaschi
Solution Sage
Solution Sage

Your question is unclear 

 

Please specify the issue clearly and usig pictures that help identify what the issue is and what is you want to get

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

krishnakanth240
Responsive Resident
Responsive Resident

Hi @cheid 

 

Build the Route-level averages (virtual table)
VAR RouteAvgTable =
SUMMARIZE(
STOPS,
STOPS[Division],
STOPS[Start of Week],
STOPS[RouteID],
"Avg_Tractor_Cnt", AVERAGE(STOPS[Longhaul Tractor Cnt]),
"Avg_Trailer_Cnt", AVERAGE(STOPS[Longhaul Trailer Cnt]),
"Avg_Tractor_Cost", AVERAGE(STOPS[Longhaul Tractor Cost]),
"Avg_Trailer_Cost", AVERAGE(STOPS[Longhaul Trailer Cost])
)


Sum those averages to Division level
Allocated Tractor Count =
SUMX(
RouteAvgTable,
[Avg_Tractor_Cnt]
)

 

Allocated Trailer Count =
SUMX(
RouteAvgTable,
[Avg_Trailer_Cnt]
)

 

Allocated Tractor Cost =
SUMX(
RouteAvgTable,
[Avg_Tractor_Cost]
)

 

Allocated Trailer Cost =
SUMX(
RouteAvgTable,
[Avg_Trailer_Cost]
)

 

If this doesn't works out, then please share the sample data with the required logic and outout. Thank You!

Ashish_Mathur
Super User
Super User

Hi,

I cannot understand your question.  Share data in a format that can be pasted in an MS Excel file.  Show the expected result clearly.


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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.