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
steveborty
New Member

Running Total for Groups of Products by Store

Hi everyone!

 

After a couple of days of trial and error I come to you for some help.

I am working on a running total of the sales (SLS) based up to a certain week (expressed as year&week number) and on products for different stores. The aim is getting a cumulative total that works at product/store level either directly on power query or on a pivot thanks to a DAX formula.

 

The starting point is an appended query with all the different years similar to the following (Running Total column just as an example):

 

StoreProductSLSSTOCKYEARWEEKRT
AAAA123082021010
AAAA123352021033
AAAA123502021048
AAAC1232102021012
AAAC123372021025
BBBA123152021021
BBBB1231192021041
BBBB1234152021055
BBBB1236920220311
CCCA1230102021010
CCCA123192021021
CCCA123452021035
CCCB1236122021046
CCCB1232102021058
CCCB1230102021068
CCCA123142021056
CCCA123-152021065

 

 

I have tried DAX options such as the following which works for the SKU but not when I select a specific Store in the Pivot as it still gives me the total cumulative of the SKU (I suppose because of the ALLEXCEPT filter.

 

= CALCULATE (
    SUM ( 'Table'[Product] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[Product] ),
        'Table'[YEARWEEK] <= MAX ( 'Table'[YEARWEEK] )
    )
)

 

 

 Do you have any idea on how I may fix this?

 

Thank you!

4 REPLIES 4
v-tangjie-msft
Community Support
Community Support

Hi  @steveborty ,

 

Try to update the measure.

Measure= CALCULATE (
    SUM ( 'Table'[Column] ),//this column depending on your needs
    FILTER (
        ALLSELECTED('Table'),
        'Table'[Product]=MAX('Table'[Product]) && 'Table'[YEARWEEK] <= MAX ( 'Table'[YEARWEEK] )
    )
)

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

sjoerdvn
Super User
Super User

try something like this

RT = VAR lw=MAX('Table'[YEARWEEK]) RETURN  CALCULATE(SUM('Table'[SLS]), 'Table'[YEARWEEK]<lw)
Greg_Deckler
Super User
Super User

@steveborty See if this helps:


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you Greg! 

Not really sure about how to implement that directly as a Pivot DAX funcion or in power query. Any suggestion?

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.