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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Nerf_Herder
Frequent Visitor

Using DIVIDE() with LAG()

I'm hoping you good folk can help as I feel like I've hit a wall.

 

I've created a calculated table with two columns 'Date' & 'Costs'. I'm trying to create a new column for the growth, from the previous row to the current row. In excel, it's an easy ([CURRENT]-[PREV])/[PREV].

 

I've tried the following, but neither work and I can't find anything on this at all:

  • Growth = DIVIDE('Table'[Costs] - LAG('Table'[Costs]), LAG('Table'[Costs]))
      Error: The syntax for 'LAG' is incorrect. (DAX(DIVIDE('Table'[Costs] - LAG('Table'[Costs]), LAG('Table'[Costs])))).
  • Growth = DIVIDE('Table'[Costs] - LAG('Table'[Costs],1), LAG('Table'[Costs],1))
      Error: The syntax for 'LAG' is incorrect. (DAX(DIVIDE('Table'[Costs] - LAG('Table'[Costs],1), LAG('Table'[Costs],1)))).
The table I'm trying to create should look like this, but it's just not happening (screenshot below).
DateCostsGrowth
2022-04£316,742.580.00%
2022-05£339,554.797.20%
2022-06£318,563.10-6.18%
2022-07£328,800.013.21%
2022-08£336,192.012.25%
2022-09£335,042.44-0.34%
2022-10£364,598.188.82%
2022-11£347,276.07-4.75%
2022-12£349,602.020.67%
2023-01£353,896.811.23%
2023-02£329,560.58-6.88%
2023-03£326,710.33-0.86%

 

Nerf_Herder_0-1682510909424.png

 

Any help would be greatly appreciated.

Thank you in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Nerf_Herder ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) Click "transform data" to enter the power query editor, change the data type of the [Costs] column to "Decimal number" type, sort the date column in ascending order, and then add the index column.

vtangjiemsft_0-1682647681940.png

vtangjiemsft_1-1682647689065.pngvtangjiemsft_2-1682647700878.pngvtangjiemsft_3-1682647737570.png

(3)Click "Close and Apply" to go back to desktop and create a calculated column.

Column = 
var _current='Table'[Costs]
var _prev=CALCULATE(SUM('Table'[Costs]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))
return DIVIDE(_current-_prev,_prev,0)

(4) Then the result is as follows.

vtangjiemsft_4-1682647873356.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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
Anonymous
Not applicable

Hi @Nerf_Herder ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) Click "transform data" to enter the power query editor, change the data type of the [Costs] column to "Decimal number" type, sort the date column in ascending order, and then add the index column.

vtangjiemsft_0-1682647681940.png

vtangjiemsft_1-1682647689065.pngvtangjiemsft_2-1682647700878.pngvtangjiemsft_3-1682647737570.png

(3)Click "Close and Apply" to go back to desktop and create a calculated column.

Column = 
var _current='Table'[Costs]
var _prev=CALCULATE(SUM('Table'[Costs]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))
return DIVIDE(_current-_prev,_prev,0)

(4) Then the result is as follows.

vtangjiemsft_4-1682647873356.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Hi @Anonymous,

 

That worked a treat, thank you so much for your help!

 

Cheers,

Ian.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors