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
EZV12
Helper IV
Helper IV

How to calculate the previous date/price before the last date/price

Hello all,

I need help to figure out a formula to calculate the previous date/price before the last date/price.  Here below please find a matrix for explanantions.  How can I apply a formula for the last 2 columes "The date before the last Start Date" & "Price before latest price"?

CustomerItemStart DateEnd DatePriceLatest Start DateLatest PriceThe date before the Last Start DatePrice before latest Price
AItem101/01/201931/12/20195 €    
AItem101/01/202030/04/20216 €  01/01/20206 €
AItem101/05/202131/12/20217 €01/05/20217 €  
BItem101/06/201731/12/20205,50 €  01/06/20175,50 €
BItem101/01/202131/12/20996,50 €01/01/20216,50 €  
CItem201/05/201831/12/20183 €    
CItem201/01/201930/06/20214 €  01/01/20194 €
CItem201/07/202131/12/20225 €01/04/20215 €  

 

Many thanks in advance for your help.

Best regards

Rachel

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

Hi, @EZV12 

Try formulas as below:

The date before the Last Start Date = 
VAR _date =
    CALCULATE (
        MAX ( 'Table'[Start Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer] = MAX ( 'Table'[Customer] )
                && 'Table'[Item] = MAX ( 'Table'[Item] )
        )
    )
VAR _datebefore =
    CALCULATE (
        MAX ( 'Table'[Start Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer] = MAX ( 'Table'[Customer] )
                && 'Table'[Item] = MAX ( 'Table'[Item] )
                && 'Table'[Start Date] < _date
        )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[Start Date] ) = _datebefore,
        _datebefore,
        BLANK ()
    )
Price before latest Price = 
VAR _date =
    CALCULATE (
        MAX ( 'Table'[Start Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer] = MAX ( 'Table'[Customer] )
                && 'Table'[Item] = MAX ( 'Table'[Item] )
        )
    )
VAR _datebefore =
    CALCULATE (
        MAX ( 'Table'[Start Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer] = MAX ( 'Table'[Customer] )
                && 'Table'[Item] = MAX ( 'Table'[Item] )
                && 'Table'[Start Date] < _date
        )
    )
VAR _price =
    CALCULATE (
        MAX ( 'Table'[Price] ),
        FILTER ( 'Table', 'Table'[Start Date] = _datebefore )
    )
RETURN
    IF ( SELECTEDVALUE ( 'Table'[Start Date] ) = _datebefore, _price, BLANK () )

55.png

Please check my sample file for more details.

 

Best Regards,
Community Support Team _ Eason

 

View solution in original post

3 REPLIES 3
v-easonf-msft
Community Support
Community Support

Hi, @EZV12 

Try formulas as below:

The date before the Last Start Date = 
VAR _date =
    CALCULATE (
        MAX ( 'Table'[Start Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer] = MAX ( 'Table'[Customer] )
                && 'Table'[Item] = MAX ( 'Table'[Item] )
        )
    )
VAR _datebefore =
    CALCULATE (
        MAX ( 'Table'[Start Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer] = MAX ( 'Table'[Customer] )
                && 'Table'[Item] = MAX ( 'Table'[Item] )
                && 'Table'[Start Date] < _date
        )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[Start Date] ) = _datebefore,
        _datebefore,
        BLANK ()
    )
Price before latest Price = 
VAR _date =
    CALCULATE (
        MAX ( 'Table'[Start Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer] = MAX ( 'Table'[Customer] )
                && 'Table'[Item] = MAX ( 'Table'[Item] )
        )
    )
VAR _datebefore =
    CALCULATE (
        MAX ( 'Table'[Start Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer] = MAX ( 'Table'[Customer] )
                && 'Table'[Item] = MAX ( 'Table'[Item] )
                && 'Table'[Start Date] < _date
        )
    )
VAR _price =
    CALCULATE (
        MAX ( 'Table'[Price] ),
        FILTER ( 'Table', 'Table'[Start Date] = _datebefore )
    )
RETURN
    IF ( SELECTEDVALUE ( 'Table'[Start Date] ) = _datebefore, _price, BLANK () )

55.png

Please check my sample file for more details.

 

Best Regards,
Community Support Team _ Eason

 

Hello @v-easonf-msft ,

Thank you very much for your help and sorry for the late reply as I thought nobody could help during several days.  I found out the solution by myself as well.

Many thanks for your time.

Best regards

Rachel

 

EZV12
Helper IV
Helper IV

Hello @v-henryk-mstf @selimovd @v-yiruan-msft ,

May you please help?

Many thanks.

Rachel

 

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.