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
lucausa75
Frequent Visitor

Error on SubTotal and GrandTotal calculation

Dear all,

I have a table like this:

Table.png

and I would like to have a grouping like this:

Pivot.png

 

As you can the column called "UNIT_QTY" gets the correct values but the subtotal and the total are not correct, in fact my "UNIT_QTY" column should contains the values in "Average of QTY" column which, for the subtotal and total, contains the summatory of the average above.

In order to fix the problem I did something with this measure: SUMX(DISTINCT(TABLE[QTY]),TABLE[QTY]) but obviously it misses the duplicated vales in the calculation; in fact in the second section with AAAA==>PHONE==> I will have (76-38) instead of (38+38).

Please, could you help me on solving this issue?

 

Thanks

1 ACCEPTED SOLUTION

Hi,

 

Please try these measures:

UNIT_QTY =
SUMX (
    GROUPBY (
        'Table',
        'Table'[CHANNEL],
        'Table'[SERVICE],
        'Table'[MODEL],
        'Table'[CODE]
    ),
    CALCULATE ( AVERAGE ( 'Table'[QTY] ) )
)
AVG PRICE =
SUMX (
    GROUPBY (
        'Table',
        'Table'[CHANNEL],
        'Table'[SERVICE],
        'Table'[MODEL],
        'Table'[CODE]
    ),
    CALCULATE ( AVERAGE ( 'Table'[PRICE] ) )
)

The result shows:

30.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

View solution in original post

8 REPLIES 8
amitchandak
Super User
Super User

Try like

AverageX(summarize(Table,table[Channel],table[Service],Table[Model],table[Code],"_1",Sum(Table[Qty])),[_1])

 

Remove/Add Group by in summarize as per need

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks for your quick reply.

 

I don't understand this "_1" in your formula: AverageX(summarize(Table,table[Channel],table[Service],Table[Model],table[Code],"_1",Sum(Table[Qty])),[_1])

 

Please could you explain?

 

If I would like to have this grouping (see values in column E) can I use your previous formula?

 

Table.png

 

Thanks

Hi,

 

Please try these measures:

UNIT_QTY =
SUMX (
    GROUPBY (
        'Table',
        'Table'[CHANNEL],
        'Table'[SERVICE],
        'Table'[MODEL],
        'Table'[CODE]
    ),
    CALCULATE ( AVERAGE ( 'Table'[QTY] ) )
)
AVG PRICE =
SUMX (
    GROUPBY (
        'Table',
        'Table'[CHANNEL],
        'Table'[SERVICE],
        'Table'[MODEL],
        'Table'[CODE]
    ),
    CALCULATE ( AVERAGE ( 'Table'[PRICE] ) )
)

The result shows:

30.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

Thanks for your feedback!

I have replaced the function GROUPBY with SUMMARIZE to be used in my PowerPivot table and it works

I'm also trying to get the same result by creating a KEY field and for each unique KEY I have to add the PRICE...

I'm new on this DAX functions...

2020-04-22 08_15_52-Start.png

 

So I'm looking for something like: "For each unique KEY take the PRICE"

 

Thanks a lot for your great support!

Hi,

 

You can still use GROUPBY function in Excel PowerPivot, see this:

31.PNG

 

Best Regards,

Giotto

 

Thanks for your example.

 

This is what happens to me when I add GROUPBY function in my PowerPivot:

 

2020-04-22 08_55_13-Start.png

 

Thanks

Hi,

 

It is related to the Excel version, please try to update your excel to the latest version.

 

Best Regards,

Giotto

@ v-gizhi-msft

 

 

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.