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.

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)