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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Abdel_BCN
Frequent Visitor

Previous value calculated column

Hello all, 

 

I hope to get a help on getting a correct previous value of the following table:

 

Abdel_BCN_0-1666803120808.png

I'm using this formula.

Abdel_BCN_1-1666803143117.png

I've tried some measures but somewhow they worked as measure but not as calculated column.

apreciated your help.

 

here the pbi file https://we.tl/t-rfxvA0vqS3

 

thanks

 

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @Abdel_BCN ,

Please try:

Previous Value = 
VAR _Cur_Date = 'Sheet1'[Date]
VAR _Pre_Date =
    CALCULATE (
        MAX ( 'Sheet1'[Date] ),
        FILTER ( ALL ( 'Sheet1' ), 'Sheet1'[Date] < _Cur_Date )
    )
VAR _Pre_Value =
    CALCULATE (
        MAX ( 'Sheet1'[Real h_M] ),
        FILTER ( ALL ( 'Sheet1' ), 'Sheet1'[Date] = _Pre_Date )
    )
RETURN
    _Pre_Value

vcgaomsft_0-1666836932062.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

3 REPLIES 3
v-cgao-msft
Community Support
Community Support

Hi @Abdel_BCN ,

Please try:

Previous Value = 
VAR _Cur_Date = 'Sheet1'[Date]
VAR _Pre_Date =
    CALCULATE (
        MAX ( 'Sheet1'[Date] ),
        FILTER ( ALL ( 'Sheet1' ), 'Sheet1'[Date] < _Cur_Date )
    )
VAR _Pre_Value =
    CALCULATE (
        MAX ( 'Sheet1'[Real h_M] ),
        FILTER ( ALL ( 'Sheet1' ), 'Sheet1'[Date] = _Pre_Date )
    )
RETURN
    _Pre_Value

vcgaomsft_0-1666836932062.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Hi @v-cgao-msft , 

 

Thanks for the solution, it works for what I want 🙂

however, I did some stress tests with repetetive days and it give wrong values.

 

Abdel_BCN_0-1666860258522.png

 

any solution to avoid this?

 

thanks anyway for your help 🙂

 

regards, 

Abdel.

Hi @Abdel_BCN ,

The problem is that the date column is not unique. Try to add an index column to the Power Query Eidtor. And use like:

Previous Value =
VAR _Cur_Index = 'Sheet1'[Index]
VAR _Pre_Index =
    CALCULATE (
        MAX ( 'Sheet1'[Index] ),
        FILTER ( ALL ( 'Sheet1' ), 'Sheet1'[Index] < _Cur_Index )
    )
VAR _Pre_Value =
    CALCULATE (
        MAX ( 'Sheet1'[Real h_M] ),
        FILTER ( ALL ( 'Sheet1' ), 'Sheet1'[Index] = _Pre_Index )
    )
RETURN
    _Pre_Value

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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