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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.