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

Preforming Excel Functions in Power Bi

Hi, 

I have this simple excel function and I am very new to DAX and measures and was wondering if there is a simple way to preform this task in power bi. In my excel I am taking the previous cell value and subtracting it from a column in a different row. I would like to repeat this process for multiple rows. I was wondering if anybody could help me with this dax formula.

 

 

HELP_PLS_0-1664526549754.png

Information about Data:

Current Improvements: measure made by subtracting two different columns 

 

My goal is for every new calcuated total the projected total value will update. 

 

Thanks!

 

5 REPLIES 5
PaulDBrown
Community Champion
Community Champion

Where are the blank rows coming from? where from are the values 2063 (goal) and the last blank line?

  Total Products Current Improvements
Blank 1615 127

 

So far I have this...

result.png

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






PaulDBrown
Community Champion
Community Champion

Please provide sample data which reflects the structure and nature of your actual data





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hello, 

This is the structure of the actual data, some of the date rows are missing a date because no date was probided, but I have the other data such as total product. Therefore, they are blank. The photos above are actual screenshots of my table in my dashboard. I have used measures, and do not columns of my measures when I am in power queary. I am trying to calculate my numbers in the "Goal" column, 

Is the original GOAL of 2603 a fixed number, does it have a source or is it stored in a table...?
EDIT: I see the initial goal is the actual total sum of Total Products, so I'll take that for the calculations.

Ok, the issue is that if you have blanks in the fact table, if you sort or reference these rows in a calculation, by default they are "sorted" as the lowest value (or "date". This is relevant because in order to achieve the Goal measure, we need the cumulative value for Current Improvements. One way to solve this is to assign dates to the blank rows (I've simply allotted them the date value of the max date in the fact table + 1 year -this will make sense when we create the date table. Basically by adding dates for the next year based on the max date which actually has values assigned to a date, we can then include blank fields in the Date Table which can be assigned to the original blank dates. Since these dates are "in the future", we can use the sorting to make calculations and display them as the last values. Make sense?).

You can do this in Power Query using the following code:

 

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "RY3LCQAxCER78RyIn9W4tSzpv41VgvEywnsO833ANNEmIxMMII5A2ONwL+4ewXoET8IuZMOkDFKaZLSyI22szKMSqXbNezvovV8zKXhdnm+GmEeaaMSCvX8=",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [DATE = _t, #"Total Products" = _t, #"Current Improvements" = _t]
  ),
  #"Changed Type" = Table.TransformColumnTypes(
    Source,
    {{"DATE", type date}, {"Total Products", Int64.Type}, {"Current Improvements", Int64.Type}}
  ),
  #"Sorted Rows" = Table.Sort(#"Changed Type", {{"DATE", Order.Ascending}}),
  #"Changed Type1" = Table.TransformColumnTypes(#"Sorted Rows", {{"DATE", type date}}),
  #"Calculated Latest" = List.Max(#"Changed Type1"[DATE]),
  #"Added Conditional Column" = Table.AddColumn(
    #"Changed Type1",
    "Custom",
    each if [DATE] = null then Date.AddYears(#"Calculated Latest", 1) else [DATE]
  ),
  #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column", {"DATE"}),
  #"Renamed Columns" = Table.RenameColumns(#"Removed Columns", {{"Custom", "New Date"}}),
  #"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns", {{"New Date", type date}})
in
  #"Changed Type2"

 

 

 

PQ.pngIf you feel more comfortable using DAX, you can add a new calculated column to the fact table using:

 

New Date =
VAR _MXDate =
    MAX ( 'fTable DAX'[DATE] )
VAR _Final =
    DATE ( YEAR ( _MXDate ) + 1, MONTH ( _MXDate ), DAY ( _MXDate ) )
RETURN
    IF ( ISBLANK ( 'fTable DAX'[DATE] ), _Final, 'fTable DAX'[DATE] )

 

 

Dax.png

In either case, you need to create the Date Table and its relationship based on the "New Date" field. Create the Date Table using (I'm referencing the table created on Power Query, so addapt the code if you have used DAX to create the extra dates in the fact Table):

Date Table =
VAR _MaxYear =
    YEAR ( MAX ( 'fTable PQ'[New Date] ) ) // Returns the max date in the fact table, which is the dates we have assigned to the blank rows
RETURN
    ADDCOLUMNS (
        CALENDAR ( MIN ( 'fTable PQ'[New Date] ), MAX ( 'fTable PQ'[New Date] ) ),
        "MonthNum", IF ( YEAR ( [Date] ) = _MaxYear, BLANK (), MONTH ( [Date] ) ),
        // ALL the IF clauses are to return a blank value if the date is in the max year
        "Month", IF ( YEAR ( [Date] ) = _MaxYear, BLANK (), FORMAT ( [Date], "MMM" ) ),
        "QuarterNum", IF ( YEAR ( [Date] ) = _MaxYear, BLANK (), QUARTER ( [Date] ) ),
        "Quarter",
            IF ( YEAR ( [Date] ) = _MaxYear, BLANK (), "Q" & QUARTER ( [Date] ) ),
        "YearSort", YEAR ( [date] ),
        // we only need this extra row to sort the following "Year" row, which is relevant to place blanks at the bottom of the visual
        "Year", IF ( YEAR ( [Date] ) = _MaxYear, BLANK (), YEAR ( [Date] ) )
    )


Note the blank values which will allow to show blanks in the visualNote the blank values which will allow to show blanks in the visual

(Note the blank fields to be used in the visual)

model.png

Sort the dates in ascending order; sort the "Year" column by the "YearSort" column

Now you can create the measures. I have created SUM measures for Total Products and Current Improvements. The Goal measure is as follows:

 

 

Goal =
VAR _InitialGoal =
    CALCULATE ( SUM ( 'fTable PQ'[Total Products] ), ALL ( 'fTable PQ' ) ) // Returns the sum for all Total Products
VAR _CumulativeImprovements =
    CALCULATE (
        SUM ( 'fTable PQ'[Current Improvements] ),
        FILTER (
            ALL ( 'Date Table' ),
            'Date Table'[Date] <= MAX ( 'Date Table'[Date] )
        )
    ) // Returns the cumulative sum of Current Improvements in ascending order by the Date Table[Date] field
RETURN
    IF (
        ISBLANK ( SUM ( 'fTable PQ'[Current Improvements] ) ),
        BLANK (),
        _InitialGoal - _CumulativeImprovements
    )

 

 

 

and you will get:

result.png

 

I've attached the sample PBIX file

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

HELP_PLS_0-1664529101334.png

For Year and Quarter, these are pulled from my date column 

Current Improvements= Measure(Column 1 - Column 2) 

 

DATETotal ProductsCurrent ImprovementsGOAL 
   2603
21-Jun1202603-0
21-Aug88252603-25
22-Jan122632578-63
22-Apr178332515-33
22-Sep453562482-56
22-Sep10802426-0
22-Oct2702426-0
Blank 16151372426-127
 2603 2289

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.