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
hprose
Helper I
Helper I

Get accurate matrix totals

Hello,

 

I have sample data in the below format. For simplicity's sake, I'm only including the customer dimension here, but my original data includes Manager, Director, etc. 

I want to create 2 matrixes from this data. One where the difference between MaxDate and MinDate is negative, one where it is positive. I have created such matrixes, but the row totals are incorrect.

 

CustomerDateAmount
A1/1/2022  5
A1/2/2022 10
A1/3/2022 10
A1/4/2022 15
A1/5/2022 20
A1/6/2022 30
B1/2/2022 40
B1/3/2022 35
B1/4/2022 40
B1/5/2022 20
B1/6/2022 15
B1/7/2022 20
C1/1/2022 15
C1/2/2022 50
C1/3/2022 100
C1/4/2022 35
C1/5/2022 100
D1/3/2022 70
D1/4/2022 50
D1/5/2022 30
D1/6/2022 20
D1/7/2022 10
E1/2/2022 100
E1/3/2022 50
E1/4/2022 70
E1/5/2022 40

 

 

Amount change = 

var MinDateAmount = CALCULATE(SUM(Sheet1[Amount]),Sheet1[Date]=MIN(Sheet1[Date]))
var MaxDateAmount = CALCULATE(SUM(Sheet1[Amount]),Sheet1[Date]=MAX(Sheet1[Date]))

return
MaxDateAmount - MinDateAmount​

 

Using the above measure, I've created 2 matrixes. I've applied a visual level filter to each where Amount Change < 0, Amount Change > 0. However, the row totals are incorrect. I understand this is because the Min and Max amounts are being calculated at the overall level, resulting in this total value. How do I make the total add up to the column total? Thanks!

Matrix Totals.png

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @hprose ,

Please try:

 

Amount change =
SUMX (
    SUMMARIZE (
        'Sheet1',
        'Sheet1'[Customer],
        "measure",
            CALCULATE ( SUM ( Sheet1[Amount] ), 'Sheet1'[Date] = MAX ( 'Sheet1'[Date] ) )
                - CALCULATE ( SUM ( Sheet1[Amount] ), 'Sheet1'[Date] = MIN ( 'Sheet1'[Date] ) )
    ),
    [measure]
)

 

vcgaomsft_0-1669174861997.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

5 REPLIES 5
hprose
Helper I
Helper I

Will do @v-cgao-msft. Works great, thanks again!

hprose
Helper I
Helper I

Works perfectly! Thank you @v-cgao-msft 

v-cgao-msft
Community Support
Community Support

Hi @hprose ,

Please try:

 

Amount change =
SUMX (
    SUMMARIZE (
        'Sheet1',
        'Sheet1'[Customer],
        "measure",
            CALCULATE ( SUM ( Sheet1[Amount] ), 'Sheet1'[Date] = MAX ( 'Sheet1'[Date] ) )
                - CALCULATE ( SUM ( Sheet1[Amount] ), 'Sheet1'[Date] = MIN ( 'Sheet1'[Date] ) )
    ),
    [measure]
)

 

vcgaomsft_0-1669174861997.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Hello @v-cgao-msft , apologies if this needs to go into a different thread. I was wondering how this measure could be modified if I wanted to get the amount difference between the first and last date, irrespective of whether the customer has data for those days.

 

For example, for A, the amount change should be -5, for B it should be 20, and so on. I was able to achieve this by hardcoding the dates in the Min and Max conditions. Can this is accomplished without hardocing the dates? Thanks again.

 

Amount Change.png

Hi @hprose ,

Yes, please consider opening a new thread next time. Thanks.

Measure:

Measure = 
VAR _min_date = CALCULATE(MIN('Sheet1'[Date]),ALL())
VAR _max_date = CALCULATE(MAX('Sheet1'[Date]),ALL())
VAR _result = CALCULATE(SUM('Sheet1'[Amount]),'Sheet1'[Date]=_max_date)-CALCULATE(SUM(Sheet1[Amount]),'Sheet1'[Date]=_min_date)
RETURN
_result

vcgaomsft_0-1669339618125.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

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.