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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
BlazejL
New Member

Calculated measure of aggregated monthly sums by weeks

Hello,

 

I'm having a problem with a measure calculations. Hoping for your help. 

 

What I want to do is to calculate difference between Value Delivered and Value Ordered in each month (please find example below). Data I have is in weeks perspective and the measure is tend to display aggregated month values for each week in a chart. Value Ordered is generated at the end of each month and it concerns order value for next month. 

 

Example for week 10 (and for all weeks in month number 3 basically):

 

Value Ordered is 26

Sum of  Value Delivered is 21

The measuer should give the result -5 (21 - 26)

 

I tried to create date values from week and year in ored to use PREVIOUSMONTH() and EARLIER() but it didn't work. I don't have a clue how to solve this problem. Do you have any advice?

 

Thanks,

Blazej

 

example.PNG

 

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @BlazejL,

 

For your requirement, you could create the formulas below.

 

Column =
VAR a =
    CALCULATE (
        MAX ( 'Table1'[Week] ),
        FILTER (
            ALLEXCEPT ( 'Table1', 'Table1'[ClientID] ),
            [Year] = EARLIER ( [Year] )
                && 'Table1'[Week] < EARLIER ( 'Table1'[Week] )
                && [Value Ordered] <> BLANK ()
        )
    )
RETURN
    LOOKUPVALUE (
        'Table1'[Value Ordered],
        Table1[Week], a,
        'Table1'[ClientID], 'Table1'[ClientID]
    )
measure =
CALCULATE (
    SUM ( Table1[Value Delivered] ),
    ALLEXCEPT ( Table1, Table1[ClientID], Table1[Month] )
)
    - SUM ( 'Table1'[Column] )

Here is the output.

 

Capture.PNG

In addition, you could refer to the attachment.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @BlazejL,

 

For your requirement, you could create the formulas below.

 

Column =
VAR a =
    CALCULATE (
        MAX ( 'Table1'[Week] ),
        FILTER (
            ALLEXCEPT ( 'Table1', 'Table1'[ClientID] ),
            [Year] = EARLIER ( [Year] )
                && 'Table1'[Week] < EARLIER ( 'Table1'[Week] )
                && [Value Ordered] <> BLANK ()
        )
    )
RETURN
    LOOKUPVALUE (
        'Table1'[Value Ordered],
        Table1[Week], a,
        'Table1'[ClientID], 'Table1'[ClientID]
    )
measure =
CALCULATE (
    SUM ( Table1[Value Delivered] ),
    ALLEXCEPT ( Table1, Table1[ClientID], Table1[Month] )
)
    - SUM ( 'Table1'[Column] )

Here is the output.

 

Capture.PNG

In addition, you could refer to the attachment.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for help @v-piga-msft.  Your solution works well! I tried your solution with additional column named "Country". It also went good.  But there is one issue that bothers me. When I changed data source to Excel file from manually inputted file it turned out that ALLECEPT() function in measure doesn't work properly. It removes context of "months" even though this is inputted in ALLEXCEPT () formula. 

 

There is a difference between Value Delivered and Value Ordered in example above but I left just Value Delivered part to simplify the issue. 

SumMths3 = CALCULATE(SUM(Sheet1[Value Delivered]), ALLEXCEPT(Sheet1, Sheet1[ClientID ],Sheet1[Country], Sheet1[Month]))

 

Do you know what is wrong here?

 

Here is a print screen snippet of the result of formula above:

 

ALLEXCEPT.PNG

 

Please find attached Power BI file with the example.

 

https://1drv.ms/u/s!AuRFJpKbTTC7hRr3s8ewROXsFnhD

 

Best Regards,

Blazej

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.