- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
DAX cannot do dynamic self referencing. Your only option is Power Query with List.Accumulate.

Helpful resources
Join us at the Microsoft Fabric Community Conference
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Power BI Monthly Update - February 2025
Check out the February 2025 Power BI update to learn about new features.

Subject | Author | Posted | |
---|---|---|---|
12-05-2023 04:52 AM | |||
11-17-2023 07:51 AM | |||
12-19-2023 08:03 AM | |||
11-10-2023 03:21 PM | |||
11-19-2023 05:47 PM |
User | Count |
---|---|
24 | |
13 | |
11 | |
10 | |
9 |
User | Count |
---|---|
18 | |
14 | |
13 | |
12 | |
10 |