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
rkammerer
Regular Visitor

How can I get the last value of a column in my dataset?

Hello,

 

I have a pricing database with different products, but the last value of some of them does not necessarily match with the last date of the dataset.

 

How can I show the last price for the columns that doesn't match to the last date? (otherwise is easy, just using lastdate() function as a filter in the calculate function).

 

I tried using the lastnonblank() function with no success. (maybe I'm using it wrong?)

 

Thanks

4 REPLIES 4
KHorseman
Community Champion
Community Champion

Perhaps you could add an index column to your table that runs from 1 to X. Then you could CALCULATE(LASTNONBLANK(Table[Column], 1), FILTER(ALL(Table), Table[Index] = MAX(Table[Index])))

 

I haven't tested it but off the top of my head that should always return the value in literal last row in Table[Column] no matter what filter context you're in. If you want filter context to restrict that column just remove the ALL().





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi KHorseman,

 

Thanks for solution. It works for me.

v-sihou-msft
Employee
Employee

Hi @rkammerer

 

In DAX, the LastNonBlank() function will not take the sort order in column, we can't directly take the last value in a column when specifying a static non blank value (like "1") as second argument in this function. Please see:

 

LASTNONBLANK and FIRSTNONBLANK functions work with any column #dax #powerpivot #ssas #tabular

 

Alternative use of FIRSTNONBLANK and LASTNONBLANK

 

So in this scenario, I think you need to get use the price as measure to get the last non blank date:

 

LASTNONBLANK (
            'Date'[Date],
            CALCULATE ( SUM ('table'[Price] ) )
        )

Then compare with the lastdate().

 

 

Regards,

Greg_Deckler
Super User
Super User

MAX?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.