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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ClaireBear
Helper I
Helper I

Convert Calculated Column into a Measure

Hi, 

 

Is there a way to convert the following calculated column into a measure? Due to the size of the report, a calculated column is throwing out a memory error. 


Calculated column:

Previous Product Price 3 =
VAR PreviousRow =
    TOPN (
        1,
        FILTER (
            Fact_PO,
            Fact_PO[Doc. Date] < EARLIER ( Fact_PO[Doc. Date] )
                && Fact_PO[Material] = EARLIER ( Fact_PO[Material] )
        ),
        Fact_PO[Doc. Date], DESC
    )
VAR PreviousValue =
    MINX ( PreviousRow, [Net Price ZAR] )
RETURN
PreviousValue

I am trying to work out the previous row value by date to determin if there has been a change in price or not. 
I then need to calculate the product % change.
The calculated column works on test data (a few rows of data) but when applied to live data, it throws out a memory error, hence the request to change it into a measure.  (the issue looks like the "earlier" function)

ClaireBear_0-1710137575718.png

 

Thank you


1 ACCEPTED SOLUTION

Hi

 

I think i found a solution

I changed the calcuation to read the following:

Measure_Previous Product Price =
VAR currDate =
    MAX ( Fact_PO[Doc. Date])
VAR currSKU =
    SELECTEDVALUE (Fact_PO[Material] )
VAR currSupplier =
    SELECTEDVALUE (Fact_PO[Name of Vendor] )
VAR prevDate =
    CALCULATE (
        MAX ( Fact_PO[Doc. Date] ),
        FILTER (
            ALLSELECTED ( Fact_PO ),
            [Doc. Date] < currDate
                && [Name of Vendor] = currSupplier
                && [Material] = currSKU
        )
    )
RETURN
    CALCULATE (
        MIN (Fact_PO[Net Price ZAR] ),
        FILTER (
            ALLSELECTED (Fact_PO ),
            [Doc. Date] = prevDate
                && [Name of Vendor] = currSupplier
                && [Material] = currSKU
        )
    )

I now get the same result:

ClaireBear_1-1710151682907.png

Thank you!

View solution in original post

6 REPLIES 6
some_bih
Super User
Super User

Hi @ClaireBear not enought infos what is grain of data you have in model and expected level of output. Still, try Measure test

PreviousValue Measure test =
VAR PreviousRow =
TOPN (
1,
FILTER (
Fact_PO,
Fact_PO[Doc. Date] < MAX ( Fact_PO[Doc. Date] )
&& Fact_PO[Material] = SELECTEDVALUE ( Fact_PO[Material] )
),
Fact_PO[Doc. Date], DESC
)
RETURN
MINX ( PreviousRow, [Net Price ZAR] )





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi

 

Thank you again, The measure unfortunaly returns a blank column. 

The table below shows the example data, and the format/structure required.
- There are 2 products with a "Net Price Zar" column by doc date.
- I have added a calculated Column (Calculated Column_Previous Product Price) which shows me the exact result i would like as a measure. 
- I want to use a "Measure" instead of a calculated column and get the same result as the "calculated column_previous product" below, same grain of data. 
- Even though the calculated column results are correct, it is throwing out a memory error with the live data which is over 100 000 rows so the calculated column is not suitable. 
- Most examples available illustrate an index or a date with the previous value calculation which is great, but my issue is that i need the date and the previous value by product in the calculation. 

So i would like the measure to show the same results as the calculated column in the example below. 

I hope this makes more sense, i appreaciate any advice. 

ClaireBear_0-1710150492767.png

 



Hi

 

I think i found a solution

I changed the calcuation to read the following:

Measure_Previous Product Price =
VAR currDate =
    MAX ( Fact_PO[Doc. Date])
VAR currSKU =
    SELECTEDVALUE (Fact_PO[Material] )
VAR currSupplier =
    SELECTEDVALUE (Fact_PO[Name of Vendor] )
VAR prevDate =
    CALCULATE (
        MAX ( Fact_PO[Doc. Date] ),
        FILTER (
            ALLSELECTED ( Fact_PO ),
            [Doc. Date] < currDate
                && [Name of Vendor] = currSupplier
                && [Material] = currSKU
        )
    )
RETURN
    CALCULATE (
        MIN (Fact_PO[Net Price ZAR] ),
        FILTER (
            ALLSELECTED (Fact_PO ),
            [Doc. Date] = prevDate
                && [Name of Vendor] = currSupplier
                && [Material] = currSKU
        )
    )

I now get the same result:

ClaireBear_1-1710151682907.png

Thank you!

Hi @ClaireBear 

So you want "just" previous row value? Your TOPN misslead me 🙂

The previous row value is based on two columns:Fact_PO[Doc. Date] and  Fact_PO[Material]

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






some_bih
Super User
Super User

Hi @ClaireBear simple create new measure with your definition.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hello, thank you. 

 

I did try this but it throws out an error:

ClaireBear_0-1710144392887.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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