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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
kostaszogo21
Frequent Visitor

How to get the value of the last date for each ID

Hello guys, 

I am relative new to Power BI and i would really appreciate all the help i can get for what seems as an easy task for all you experts.
I have a table that looks like this:

kostaszogo21_0-1650979993207.png

 What i want to do is find the last (according to date) non-blank value and put it in a new column. That value has to be shown in all the rows of the connection_id. So my desired result will have to look like that:

kostaszogo21_1-1650980281656.png

 

Unfortunately no pbix file is available. I am just looking for the DAX that will allow me to create that new column.
I know you got it guys and you will sure make me look good to my boss!
Thanks in advance

2 ACCEPTED SOLUTIONS
moizsherwani
Continued Contributor
Continued Contributor

@kostaszogo21  here is my solution, I am sure there are more efficient ways which I will be happy to learn from my fellow experts / super users. I have also attached the sample pbix file for your reference.

 

moizsherwani_0-1650983346668.png

 

LastNonBlankValue = 
VAR MaxNonBlankDateForConnection =
    CALCULATE (
        MAX ( SampleData[date] ),
        FILTER (
            SampleData,
            SampleData[value] <> ""
                && NOT ( ISBLANK ( SampleData[value] ) )
                    && SampleData[connection_id] = EARLIER ( SampleData[connection_id] )
        )
    )
RETURN
    CALCULATE (
        MAX ( SampleData[value] ),
        FILTER (
            SampleData,
            SampleData[connection_id] = earlier(SampleData[connection_id])
                && SampleData[date] = MaxNonBlankDateForConnection
        )
    )

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

View solution in original post

SpartaBI
Community Champion
Community Champion

@kostaszogo21 

Last non-blank value =
VAR _id = 'Table'[connection_id]
VAR _last_availble_date =
    CALCULATE (
        MAX ( 'Table'[date] ),
        REMOVEFILTERS ( 'Table' ),
        'Table'[connection_id] = _id,
        'Table'[value] <> BLANK ()
    )
VAR _result =
    CALCULATE (
        MAX ( 'Table'[value] ),
        'Table'[date] = _last_availble_date,
        'Table'[connection_id] = _id,
        REMOVEFILTERS ()
    )
RETURN
    _result

View solution in original post

4 REPLIES 4
SpartaBI
Community Champion
Community Champion

@kostaszogo21 

Last non-blank value =
VAR _id = 'Table'[connection_id]
VAR _last_availble_date =
    CALCULATE (
        MAX ( 'Table'[date] ),
        REMOVEFILTERS ( 'Table' ),
        'Table'[connection_id] = _id,
        'Table'[value] <> BLANK ()
    )
VAR _result =
    CALCULATE (
        MAX ( 'Table'[value] ),
        'Table'[date] = _last_availble_date,
        'Table'[connection_id] = _id,
        REMOVEFILTERS ()
    )
RETURN
    _result

It works as well! Thanks SpartaBI

moizsherwani
Continued Contributor
Continued Contributor

@kostaszogo21  here is my solution, I am sure there are more efficient ways which I will be happy to learn from my fellow experts / super users. I have also attached the sample pbix file for your reference.

 

moizsherwani_0-1650983346668.png

 

LastNonBlankValue = 
VAR MaxNonBlankDateForConnection =
    CALCULATE (
        MAX ( SampleData[date] ),
        FILTER (
            SampleData,
            SampleData[value] <> ""
                && NOT ( ISBLANK ( SampleData[value] ) )
                    && SampleData[connection_id] = EARLIER ( SampleData[connection_id] )
        )
    )
RETURN
    CALCULATE (
        MAX ( SampleData[value] ),
        FILTER (
            SampleData,
            SampleData[connection_id] = earlier(SampleData[connection_id])
                && SampleData[date] = MaxNonBlankDateForConnection
        )
    )

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Thanks so much Moiz!!!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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