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
Alezy
New Member

Get the value for the previous non blank date

Hi everybody,

I'm trying to calculate a Day On Day Change for a set of stocks. The thing is, when it comes to getting the previous day value, there are sometimes where Dax returns me a blank value since there's a weekend in between. 

I guess this is because my formula has flaws... I'd like just to have the previous day value as it happens when it's labour day. 

Formula and tables are:

 

Latest ULSD 10ppm MED (€/l) = CALCULATE (

     AVERAGE('ULSD 10ppm CIF MED'[Litres EUR Prevat]),

     FILTER ('ULSD 10ppm CIF MED',

         'ULSD 10ppm CIF MED'[Date]

             = CALCULATE (

                 LASTNONBLANK ( 'ULSD 10ppm CIF MED'[Date], 1 ),

                 FILTER (

                     'ULSD 10ppm CIF MED',

                      'ULSD 10ppm CIF MED'[Date] <= LASTDATE( 'ULSD 10ppm CIF MED'[Date])))))
PR ULSD 10ppm MED CIF Cargoes (€/l) = 
IF(ISBLANK([Latest ULSD 10ppm MED (€/l)]),
 [Latest ULSD 10ppm MED (€/l)],
    CALCULATE (
     AVERAGE('ULSD 10ppm CIF MED'[Litres EUR Prevat]),
        PREVIOUSDAY('CALENDAR'[Date])))
DoD Change ULSD 10ppm MED CIF Cargoes (€/l) = 
Var Division = DIVIDE([Latest ULSD 10ppm MED (€/l)] - [PR ULSD 10ppm MED CIF Cargoes (€/l)], [PR ULSD 10ppm MED CIF Cargoes (€/l)])
Return
Division 

 

Alezy_0-1685950259764.png

 

Expected Results are: 

DateLitres EUR Prevat (Current)Prev. ValueDoD
02/06/20231.06181.05420.0072
01/06/20231.05421.04110.0126
31/05/20231.04111.0453-0.0040
30/05/20231.04531..0591-0.0130
29/05/20231.05911.0598-0.0006
26/05/20231.05981.05080.0086

 

Appreciate any help.

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Alezy 
Please try

PR ULSD 10ppm MED CIF Cargoes (€/l) =
VAR CurrentDate =
    MAX ( 'CALENDAR'[Date] )
RETURN
    AVERAGEX (
        TOPN (
            1,
            FILTER (
                ALLSELECTED ( 'ULSD 10ppm CIF MED' ),
                'ULSD 10ppm CIF MED'[Date] < CurrentDate
            ),
            'ULSD 10ppm CIF MED'[Date]
        ),
        'ULSD 10ppm CIF MED'[Litres EUR Prevat]
    )

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Alezy 
Please try

PR ULSD 10ppm MED CIF Cargoes (€/l) =
VAR CurrentDate =
    MAX ( 'CALENDAR'[Date] )
RETURN
    AVERAGEX (
        TOPN (
            1,
            FILTER (
                ALLSELECTED ( 'ULSD 10ppm CIF MED' ),
                'ULSD 10ppm CIF MED'[Date] < CurrentDate
            ),
            'ULSD 10ppm CIF MED'[Date]
        ),
        'ULSD 10ppm CIF MED'[Litres EUR Prevat]
    )

That's exactly what I needed. Thanks a lot!

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.