+ Reply to Thread
Results 1 to 6 of 6

[Power Query] Summing values across all dimensions except one

  1. #1
    Registered User
    Join Date
    12-21-2018
    Location
    Egypt
    MS-Off Ver
    Office 365 64-bit
    Posts
    20

    [Power Query] Summing values across all dimensions except one

    Hello Gurus!

    I am seeking your help again with a task at hand which I found a bit complicated.

    In the warehouse, we take a snapshot of the "Closing Stock" by end of each month. It makes sense to aggregate the closing stock by several dimensions such as "Production Line", "Production Plant", etc..., but it doesn't make any sense to aggregate the closing stocks for several time periods because it would be meaningless.

    1.JPG

    For example, if I am looking at the stock closing of a quarter, let's say Q1-2023, it shouldn't add Jan + Feb + Mar, but instead it should only look at Mar-2023 as the closing stock for this quarter, and add everything under March-2023 only.

    2.JPG

    Similarly, if I am looking at all data without adding any time dimension, it should add the closing stocks under the last month in the dataset, but *not* add the closing stock for all months because it doesn't mean anything.

    3.JPG

    I have added a detailed sample file with what I'm trying to achieve and the expected results. Could you please help me write the DAX formula that would achieve that objective?

    The logic I have in mind would be basically to tell Excel to "SUM everything under the last month you find under any selection".

    Thank You!

    Sample Data for Closing Stock Aggregation.xlsx

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,053

    Re: [Power Query] Summing values across all dimensions except one

    Does it have to be PQ and DAX? Or are you open to 365 solutions?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    12-21-2018
    Location
    Egypt
    MS-Off Ver
    Office 365 64-bit
    Posts
    20

    Re: [Power Query] Summing values across all dimensions except one

    Hi Ali,

    Unfortunately I'm stuck with PQ and DAX because this problem is a part of a huge data model made using PQ.

    Thank You.

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    19,027

    Re: [Power Query] Summing values across all dimensions except one

    An easy way to accomplish this is to add months to the Filters area of the Field List, and choose the months applicable to each pivot table.
    Note that in the top pivot table the Grand Total will not be just a repeat of the closing stock for December, so you may want to show Grand Total for columns only.
    Note that in the bottom pivot table the Grand Total for rows will not display anyway.
    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  5. #5
    Registered User
    Join Date
    12-21-2018
    Location
    Egypt
    MS-Off Ver
    Office 365 64-bit
    Posts
    20

    Re: [Power Query] Summing values across all dimensions except one

    Hi JeteMC,

    Thank you for your reply. I don't think it would be usable in my case because the data is dynamic and I need the model to be able to calculate properly on its own.

    I have managed to resolve it finally after a few trials using a simple DAX equation. I got the idea when I started breaking down the solution on a piece of paper.

    Solution.JPG

    Resolved.JPG

    Solution Workbook: Sample Data for Closing Stock Aggregation (DAX Solution).xlsx

    Thank You.

  6. #6
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    19,027

    Re: [Power Query] Summing values across all dimensions except one

    Glad that you found a solution. Thank You for the feedback and for marking the thread as 'Solved'. I hope that you have a blessed day.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 10-31-2023, 11:12 AM
  2. Power Query - Feeding dynamic sheet name to Power query
    By egoosen3 in forum Excel General
    Replies: 5
    Last Post: 09-13-2023, 07:41 AM
  3. [SOLVED] [Power Query] How to filter 0 from two columns in power query editor in one step?
    By daliye in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2023, 09:44 PM
  4. Replies: 1
    Last Post: 07-14-2023, 10:15 AM
  5. Replies: 4
    Last Post: 04-20-2023, 04:02 AM
  6. Replies: 4
    Last Post: 02-17-2020, 06:03 AM
  7. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1