cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Devilstar
Frequent Visitor

get last value from Date

Hello,

 

i am trying to get the last value from a date. This value should be use for the month before which are null.

 

The initial situation looks like that:

 

initial-situation

 

After a DAX-Function the result should look like this:

 

 

result

 

About help or solution suggestions, I would be very happy!

 

Thanks,

alex

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: get last value from Date

HI, @Devilstar

You could try this formula to add a column as below:

Value 2 = 
VAR CurrentCar = 'Table'[Car]
VAR CurrentDate = 'Table'[Month]
VAR CurrentRegion = 'Table'[region]
VAR LastDateWithValue =
    IF (
        ISBLANK ( 'Table'[Value] ) = FALSE (),
        'Table'[month],
        CALCULATE (
            MIN ( 'Table'[month] ),
            FILTER (
                'Table',
                'Table'[car] = EARLIER ( 'Table'[car] )
                    && 'Table'[region] = EARLIER ( 'Table'[region] )
                    &&'Table'[month]>=EARLIER('Table'[month])
                    && ISBLANK ( 'Table'[Value] ) = FALSE ()
            )
        )
    )
RETURN
    VAR A =
        CALCULATE (
            LASTNONBLANK(  'Table'[Value], 'Table'[Value] ),
            FILTER (
                'Table',
                'Table'[Car] = CurrentCar
                    &&  'Table'[Month]  = LastDateWithValue
                    && 'Table'[region] = CurrentRegion
            )
        )
    RETURN
        IF ( ISBLANK ( 'Table'[Value] ), A, 'Table'[Value] )

Result:

2018120312.JPG2018120313.JPGDeeper testing

 

Best Regards,

Lin

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Super User I
Super User I

Re: get last value from Date

Looks like a good candidate for Fill Up in the Power Query Editor(Transform).

It only works for null entries, remember so you may have to use Replace first.

Devilstar
Frequent Visitor

Re: get last value from Date

thank you for your suggestion! With the function Fill Up it works (with import from SAP BW).

 

But i want to use in the next time direct query (on SAP BW), so i have to solve it with a function.

 

On this topic there is nearly the same problem case:

https://community.powerbi.com/t5/Desktop/Fill-blanks-with-previous-value/m-p/492572#M229548

 

i change there solotion for my case:

Value2 = 
VAR CurrentCar = 'Table'[Car]
VAR CurrentDate = 'Table'[Month]
VAR CurrentRegion = 'Table'[region]
VAR LastDateWithValue =
    CALCULATE (
        MAX ( 'Table'[Month] );
        FILTER (
            'Table';
            'Table'[Value] <> BLANK ()
                && 'Table'[Car] = CurrentCar
                && 'Table'[Month] = CurrentDate
                && 'Table'[region] = CurrentRegion
        )
    )
Return
    CALCULATE (
        LASTNONBLANK('Table'[Value];'Table'[Value]);
        FILTER (
            'Table';
            'Table'[Car] = CurrentCar
                && 'Table'[Month] > LastDateWithValue
                && 'Table'[region] = CurrentRegion
                      )
    )

Now it looks like that:

result 2.JPG

 

Unfortunately, it is not the solution yet....

 

if would like to have a formula like this:

value3 = if('Table'[Value]=BLANK();"get last Value";"nothing")

 

Have anyone a solution?

 

Thanks,

alex

 

 

Highlighted
affan Solution Sage
Solution Sage

Re: get last value from Date

Hi @Devilstar,

 

You can use the below DAX to create the custom column.

 

Value2 = 
VAR CurrentCar = 'Table'[Car]
VAR CurrentDate = 'Table'[Month]
VAR CurrentRegion = 'Table'[region]
VAR _LastDateWithValue =
    CALCULATE (
        MIN ( 'Table'[Month] ),
        FILTER (
            'Table',
            'Table'[Value] <> BLANK ()
                 && 'Table'[Car] = CurrentCar
                && 'Table'[Month] > CurrentDate
                && 'Table'[region] = CurrentRegion
        )
    )
var _result=   IF(ISBLANK('Table'[Value]), CALCULATE (
        FIRSTNONBLANK('Table'[Value],1),
        FILTER (
            'Table',
            'Table'[Car] = CurrentCar
                && 'Table'[Month] = _LastDateWithValue
                && 'Table'[region] = CurrentRegion
                      )
    ),'Table'[Value])
Return
_result

Below is the result I have got from the above expression.

 

Min value for date.png

You can see the pbix file for your reference.

 

 

If this helped you, please mark this post as an accepted solution and like to give KUDOS .

 

Regards,

Affan

 

 

Community Support
Community Support

Re: get last value from Date

HI, @Devilstar

You could try this formula to add a column as below:

Value 2 = 
VAR CurrentCar = 'Table'[Car]
VAR CurrentDate = 'Table'[Month]
VAR CurrentRegion = 'Table'[region]
VAR LastDateWithValue =
    IF (
        ISBLANK ( 'Table'[Value] ) = FALSE (),
        'Table'[month],
        CALCULATE (
            MIN ( 'Table'[month] ),
            FILTER (
                'Table',
                'Table'[car] = EARLIER ( 'Table'[car] )
                    && 'Table'[region] = EARLIER ( 'Table'[region] )
                    &&'Table'[month]>=EARLIER('Table'[month])
                    && ISBLANK ( 'Table'[Value] ) = FALSE ()
            )
        )
    )
RETURN
    VAR A =
        CALCULATE (
            LASTNONBLANK(  'Table'[Value], 'Table'[Value] ),
            FILTER (
                'Table',
                'Table'[Car] = CurrentCar
                    &&  'Table'[Month]  = LastDateWithValue
                    && 'Table'[region] = CurrentRegion
            )
        )
    RETURN
        IF ( ISBLANK ( 'Table'[Value] ), A, 'Table'[Value] )

Result:

2018120312.JPG2018120313.JPGDeeper testing

 

Best Regards,

Lin

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Devilstar
Frequent Visitor

Re: get last value from Date

thanks! This works 🙂

 

Best regards

Alex

Helpful resources

Announcements
Announcing the New Spanish Forum

Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

April 2020 Community Highlights

April 2020 Community Highlights

Info on our Super Users, MBAS content and badges, and updates to our support articles. - Read the full Community Highlights.

MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Top Solution Authors
Top Kudoed Authors