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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
LadyPeshet
Regular Visitor

Calculation in DAX or Power Query based on Excel formula

Hello,

I have following calculation and I need to create results in Power BI that are right now placed in the last column "Diff Amount". Diff Amount doesn't exist currently in Power BI model.

   Monthly Amount  = column B

   Minimum Monthly Amount   = column C

   Diff Amount = column D

    Monthly Amount      Minimum Monthly Amount      Diff Amount
Month   
01.2011   200   100   0
02.2011   100   100   0
03.2011   90   100  10
04.2011   103   100   7
05.2011   110   100   0
06.2011   50   100   50
07.2011   140   100   10
08.2011    115   100   0
09.2011   100   100   0

 

Excel formula is following: =IF((C3-B3+D2)<0;0;(C3-B3+D2))

 

"Diff Amount" is referencing to previous row results. First two column are already in datasource. Is it possible to replicate third column without phisically adding it to the datasource? Would it be possible to calculate it using custom function in Power Query or by using DAX?

 

Thank you in advance for your help!

 

 

2 REPLIES 2
BeaBF
Super User
Super User

@LadyPeshet  Here a sample code:

Diff Amount =
VAR CurrentRow = YourTable[Monthly Amount]
VAR PreviousDiff = IF(MAX(YourTable[Month]) <> MIN(YourTable[Month]), LOOKUPVALUE(YourTable[Diff Amount], YourTable[Month], MAX(YourTable[Month])-1), 0)
RETURN
IF((YourTable[Minimum Monthly Amount] - CurrentRow + PreviousDiff) < 0, 0, YourTable[Minimum Monthly Amount] - CurrentRow + PreviousDiff)

BBF

lbendlin
Super User
Super User

DAX cannot do dynamic self referencing.  Your only option is Power Query with List.Accumulate.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.