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
giuliapiazza94
Helper IV
Helper IV

Different sum based on type column

Hi guys,

I've a table like this

giuliapiazza94_1-1713424365289.png

 

This table is linked to calendar table.

In report I use a filter to set a time period, for example: from 19/03/2024 to 30/04/2024.

I need to create a matrix:

 

Type    amount

A         ..........

B         ...........

 

My measure must calculate the sum of type A from beginning of the year to until the day before the period I selected (18/03/2024) and the sum of type B from 19/03/2024 to 30/04/2024.

 

filter date:  from 19/03/2024 to 30/04/2024

 

For example:

Type     amount

A             600+120+23+77=820

B             1+72=72

 

Thank you all 🙂

 

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

Thanks for the reply from @tamerj1 , please allow me to provide another insight: 


Hi  @giuliapiazza94 ,

Here are the steps you can follow:

1. Create calculated table – slicer table.

Date =
CALENDAR(
    DATE(2024,1,1),DATE(2024,4,30))

2. Create measure.

Measure =
var _mindate=MINX(ALLSELECTED('Date'),'Date'[Date])
var _maxdate=MAXX(ALLSELECTED('Date'),'Date'[Date])
var _perioddate=_mindate-1
var _until=
DATE(YEAR(_mindate),1,1)
return
IF(
    MAX('Table'[Type])="A",
    SUMX(
        FILTER('Table',
      'Table'[Date]>=_until&&'Table'[Date]<=_perioddate),[Amount]),
    SUMX(
        FILTER('Table',
       'Table'[Date]>=_mindate&&'Table'[Date]<=_maxdate),[Amount]))

3. Result:

 

vyangliumsft_0-1713494767419.png

 

Best Regards,

Liu Yang

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-yangliu-msft
Community Support
Community Support

Thanks for the reply from @tamerj1 , please allow me to provide another insight: 


Hi  @giuliapiazza94 ,

Here are the steps you can follow:

1. Create calculated table – slicer table.

Date =
CALENDAR(
    DATE(2024,1,1),DATE(2024,4,30))

2. Create measure.

Measure =
var _mindate=MINX(ALLSELECTED('Date'),'Date'[Date])
var _maxdate=MAXX(ALLSELECTED('Date'),'Date'[Date])
var _perioddate=_mindate-1
var _until=
DATE(YEAR(_mindate),1,1)
return
IF(
    MAX('Table'[Type])="A",
    SUMX(
        FILTER('Table',
      'Table'[Date]>=_until&&'Table'[Date]<=_perioddate),[Amount]),
    SUMX(
        FILTER('Table',
       'Table'[Date]>=_mindate&&'Table'[Date]<=_maxdate),[Amount]))

3. Result:

 

vyangliumsft_0-1713494767419.png

 

Best Regards,

Liu Yang

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

tamerj1
Super User
Super User

Hi @giuliapiazza94 
Please try

AmountMeasure =
SUMX (
    VALUES ( 'Table'[Type] ),
    IF (
        'Table'[Type] = "A",
        CALCULATE (
            SUM ( 'Table'[Amount] ),
            'Calendar'[Date] < MIN ( 'Calendar'[Date] )
        ),
        SUM ( 'Calendar'[Amount] )
    )
)

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.