cancel
Showing results for
Did you mean:
Helper II

## Calculation on values on the same column

Dear All,

I need to make a subtraction between two values on the same Column.

In my table I have the quantity of each ITEM at the end of the moth.

I need to add another column with the delta between two consecutive months:

quantity of February - quantity of Jannuary

quantity of March - quantity of Febrary

...

 ITEM date Quantity delta V32 31.01.2021 34 V32 28.02.2021 77 43 V32 31.03.2021 30 -47 M37 31.01.2021 46 M37 28.02.2021 28 -18 M37 31.03.2021 55 27

PowerQuery using M or Dax in PowerBI is both ok.

Paolo

1 ACCEPTED SOLUTION
Community Support

You can create a calculate column using DAX by filtering with end of previous month.

Column =
var pre_eom= ENDOFMONTH(PREVIOUSMONTH('Table'[date]))
var pre_eom_quantity = CALCULATE(SUM([Quantity]),FILTER('Table',[TEM]=EARLIER([TEM]) && [date]=pre_eom))
Return IF(ISBLANK(pre_eom_quantity),BLANK(),[Quantity]-pre_eom_quantity)

If you don't want the blank, just use: Return [Quantity]-pre_eom_quantity

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

2 REPLIES 2
Community Support

You can create a calculate column using DAX by filtering with end of previous month.

Column =
var pre_eom= ENDOFMONTH(PREVIOUSMONTH('Table'[date]))
var pre_eom_quantity = CALCULATE(SUM([Quantity]),FILTER('Table',[TEM]=EARLIER([TEM]) && [date]=pre_eom))
Return IF(ISBLANK(pre_eom_quantity),BLANK(),[Quantity]-pre_eom_quantity)

If you don't want the blank, just use: Return [Quantity]-pre_eom_quantity

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

Community Champion

Hi, @paolomint

Please check the below picture and the sample pbix file's link down below for creating a new column.

Delta CC =
VAR currentitem = 'Table'[ITEM]
VAR rankingbydate =
RANKX ( FILTER ( 'Table', 'Table'[ITEM] = currentitem ), 'Table'[date],, ASC )
VAR previousquantity =
MAXX (
FILTER (
'Table',
'Table'[ITEM] = currentitem
&& RANKX ( FILTER ( 'Table', 'Table'[ITEM] = currentitem ), 'Table'[date],, ASC ) = rankingbydate - 1
),
'Table'[Quantity]
)
RETURN
IF ( NOT ISBLANK ( previousquantity ), 'Table'[Quantity] - previousquantity )

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Best regards, JiHwan Kim

Announcements