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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
leolapa_br
Resolver II
Resolver II

Get First Value From A Column

Hi have a table called "StockQuotes" that looks like this:

StockQuotes_Sample.png

I wrote the following code as an attempt to fetch the first available (from the earliest date) Close Price for each respective stock ticker:

First Close = 
  VAR Ticker = SELECTEDVALUE( StockQuotes[Ticker] )
  VAR Result = MINX (
    TOPN (
        1,
        FILTER ( StockQuotes, StockQuotes[Ticker] = Ticker ),
        StockQuotes[Date], ASC
    ),
    StockQuotes[Close Price]
)
RETURN
  Result

I then created the matrix visual below with the dates along the rows and stock tickers across the top to check whether the above code produced the desired results:

Matrix_Sample.png

But as it can be seen the code it's not working since I was expecting the matrix to return repeated numbers under the First Close column for each respective ticker (i.e.: $63.96 for AAPL, $89.57 for AMZN, $323,400.00 for BRK-A, $63.69 for GOOG and so on...), not a mirror image of the Close Price column.

 

What am I missing here?

 

Any help on getting to the right code is greatly apreciated!

1 ACCEPTED SOLUTION
leolapa_br
Resolver II
Resolver II

ChatGTP came to the rescue here and produced the following code that solved the issue:

First Close = 
CALCULATE(
    FIRSTNONBLANK(StockQuotes[Close Price], 1),
    FILTER(
        ALL(StockQuotes),
        StockQuotes[Ticker] = SELECTEDVALUE(StockQuotes[Ticker]) &&
        StockQuotes[Date] = 
            CALCULATE(
                MIN(StockQuotes[Date]),
                ALLEXCEPT(StockQuotes, StockQuotes[Ticker])
            )
    )
)

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @leolapa_br ,

 

Thanks for sharing, this will help other users who have the same question.

 

 

Best regards,

Mengmeng Li

 

 

leolapa_br
Resolver II
Resolver II

ChatGTP came to the rescue here and produced the following code that solved the issue:

First Close = 
CALCULATE(
    FIRSTNONBLANK(StockQuotes[Close Price], 1),
    FILTER(
        ALL(StockQuotes),
        StockQuotes[Ticker] = SELECTEDVALUE(StockQuotes[Ticker]) &&
        StockQuotes[Date] = 
            CALCULATE(
                MIN(StockQuotes[Date]),
                ALLEXCEPT(StockQuotes, StockQuotes[Ticker])
            )
    )
)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.