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
Mainer04401
Helper III
Helper III

Sum of average sales at the postal code level

I have sales data for my stores and in another column on the same worksheet I have the aggregate sales of all stores in that same postal code (the trading area).

Trouble is, when I have multiple stores in the same zip code, the trading area's sales are duplicated. For example, if I have 3 stores in the same zip code, the trading area sales are listed 3x.
 
I thought I had a working formula below:

sumx(values(Table[Postal Code]),
calculate(average(Table[Trading Area Sales),
allexcept(Table,Table[Postal Code],Table[Product],Table[Week])))
 
This calculates a sum of the average sales in each postal code.
 
I chose average because I thought it would solve the issue of trading area sales being repeated. Unfortunately, this only works when I have one time period and one product in the view or filtered. Otherwise, in my example of 3 stores in the same postal code, instead of dividing the sum by 3, it would divide the sum by 6 if I have 2 products selected. Any suggestions on a better formula?
 
Here is a table to illustrate what I'm trying to accomplish ...  The postal code sales column takes an average of all sales at the postal code level and then sums the averages in the total. 
Store NamePostal CodeSalesPostal Code Sales
Store A063851001,000
Store B063852001,000
Store C902103003,000
Store D902103003,000
TOTAL 900

4,000

1 ACCEPTED SOLUTION

Hi @Mainer04401 ,

 

try this

SUMX (
    SUMMARIZE (
        'Table',
        'Table'[Postal Code],
        'Table'[Product],
        'Table'[Week],
        "@AVG", CALCULATE (
            AVERAGE ( 'Table'[Trading Area Sales] ),
            ALLEXCEPT ( 'Table', 'Table'[Postal Code], 'Table'[Product], 'Table'[Week] )
        )
    ),
    [@AVG]
)

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


View solution in original post

4 REPLIES 4
Mainer04401
Helper III
Helper III

The formula below APPEARS to do what I need but if there is a cleaner, more efficient way, I would love to hear it!

 

sumx(values(Table[Postal Code]),

sumx(values(Table[Product]),

sumx(values(Table[Week],
calculate(average(Table[Trading Area Sales),
allexcept(Table,Table[Postal Code],Table[Product],Table[Week])))

 

Essentially I need PowerBI to sum the average of each product's sales, during each week, at the postal code level in order to remove duplicates at the postal code level.

Hi @Mainer04401 ,

 

try this

SUMX (
    SUMMARIZE (
        'Table',
        'Table'[Postal Code],
        'Table'[Product],
        'Table'[Week],
        "@AVG", CALCULATE (
            AVERAGE ( 'Table'[Trading Area Sales] ),
            ALLEXCEPT ( 'Table', 'Table'[Postal Code], 'Table'[Product], 'Table'[Week] )
        )
    ),
    [@AVG]
)

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


@mwegener- Thank you!  That worked and that formula loads much quicker than the formula I used so it must be much more efficient!  

amitchandak
Super User
Super User

Refer to this

https://community.powerbi.com/t5/Desktop/SUM-of-AVERAGE/td-p/197013

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect 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.