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
iago_salvadori1
Frequent Visitor

How to calculate a cumulative measure by id's month?

Hello Power bi community,

 

I have the following data: MONTH_ID, PRODUCT, YEAR AND ID_CODE.

 

I would like to create a measure that would result in a column with the same behavior as the column "RESULT":

iago_salvadori1_1-1641293114931.png

I tried to create a measure, but doesn't have the result expect. 

Result = CALCULATE([TOTAL],
         FILTER(
         ALL('TABLE1'[MONTH_ID]),
         'TABLE1'[MONTH_ID] < MAX('TABLE1'[MONTH_ID]))

 

The measure must be the value up to the previous month of the filter, that is, if no filter is defined MONTH_ID = 10, the cumulative result must be up to MONTH_ID = 9

 

1 ACCEPTED SOLUTION

Hi @iago_salvadori1 ,

 

Here I have a test by your sample data. I think you can use "less or equal to" function in your filter and you can achieve your goal.

Quantity CUMULATIVE (Category 10) =
CALCULATE (
    [Quantity MONTHLY (Category 10)],
    FILTER (
        ALL ( Table1[ID_MONTH] ),
        Table1[ID_MONTH]
            <= MAX ( Table1[ID_MONTH] ) - 1
    )
)

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
amitchandak
Super User
Super User

@iago_salvadori1 , Not able to related total and result,

 

You need like

 

Result = CALCULATE([TOTAL],
FILTER(
ALL('TABLE1'[MONTH_ID]),
'TABLE1'[MONTH_ID] < MAX('TABLE1'[MONTH_ID]) - 1 )

 

 

Or have year month table/ date
new column , in a new month year table

Month Rank = RANKX(all('Date'),'Date'[MMonth Year],,ASC,Dense)

 

The try measure like 

Result = CALCULATE([TOTAL],
FILTER(
ALL('Date'),
'Date'[Month Rank] < MAX('TABLE1'[Month Rank]) - 1 )

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Hello @amitchandak, thanks your suggestion.

 

I don't know how to send Pbix here, but I'll send the table with the data:

ID_COMPANYID_CATEGORYID_MONTHPRODUCTYEARCLIENTQTD
5600101Product A2021110540
5400101Product B2021100130
5600102Product C2021100130
5600103Product A2021100110
5400103Product A2021110540
5400104Product A2021110550
5400105Product A2021100110
5600106Product C202110025
5600107Product C202111055
5600108Product B20211107100
54001010Product D2021110530
5500109Product B2021110510
55001011Product Z2021100130
54001011Product A2021110525
5600203Product Z2021100120
5600204Product A2021110560
54001012Product B2021110730
5500107Product C2021100110

 

I create two measures:

 

Quantity MONTHLY (Category 10) = 
CALCULATE(
SUMX(Table1,Table[QTD]),Table1[ID_CATEGORY] = 10)
Quantity CUMULATIVE (Category 10) = 
CALCULATE([Quantity MONTHLY (Category 10)],
FILTER(
ALL(Table1[ID_MONTH]),
Table1[ID_MONTH] < MAX(Table1[ID_MONTH]) - 1))

 

With the following filters in the chart:

iago_salvadori1_0-1641313345930.png

Graph result:

iago_salvadori1_1-1641313433624.png

The measure CUMULATIVE Quantity  (Category 10) has the wrong result 330, It should be 340.

Hi @iago_salvadori1 ,

 

Here I have a test by your sample data. I think you can use "less or equal to" function in your filter and you can achieve your goal.

Quantity CUMULATIVE (Category 10) =
CALCULATE (
    [Quantity MONTHLY (Category 10)],
    FILTER (
        ALL ( Table1[ID_MONTH] ),
        Table1[ID_MONTH]
            <= MAX ( Table1[ID_MONTH] ) - 1
    )
)

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

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.