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
Rickmaurinus
Helper V
Helper V

Get the most recent stock value in weekends

Dear community,

 

I'm currently making a dashboard to track an investment portfolio. It consists of several queries. 

 

There's a calendar, a query with the times that stocks were bought called transactions (with the amount and price), and there's a query with the daily stock values called Allprices. I added a screenshot of how the data looks. 

 

The values of the stocks don't change in the weekends. So there's only weekdays that mutate. I would like to make a measure in Power BI, that takes the latest known stock value in the weekend. So that on saturdays and sundays, the value would be taken from friday.  Currently, by taking a SUM of the stockprice, I get the values of measure "StockPrice". 

 

I've tried to come up with a formula to get the values from friday, in the weekends. I've been juggling around with a LASTNONBLANK formula, but don't get it to work. I hope somebody has a suggestion to help me out there. I get the feeling I don't take into account the Dates, or perhaps the other investment funds. 

 

 

Formula.pngAllPrices.pngTransactions.png

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

@Rickmaurinus,

Create the measure using DAX below and check if you get expected result.

Teststock2 = 
VAR LastNonBlankDate =
    CALCULATE (
        LASTNONBLANK ( 'Calendar'[Date], 1 ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date]<= MAX('Calendar'[Date])
                && NOT ( ISBLANK ( [Stockedprice] ) )
        )
    )
RETURN
    CALCULATE (
        [Stockedprice],
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date]= LastNonBlankDate )
    )



Regards,
Lydia

Community Support Team _ Lydia Zhang
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

2 REPLIES 2
v-yuezhe-msft
Employee
Employee

@Rickmaurinus,

Create the measure using DAX below and check if you get expected result.

Teststock2 = 
VAR LastNonBlankDate =
    CALCULATE (
        LASTNONBLANK ( 'Calendar'[Date], 1 ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date]<= MAX('Calendar'[Date])
                && NOT ( ISBLANK ( [Stockedprice] ) )
        )
    )
RETURN
    CALCULATE (
        [Stockedprice],
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date]= LastNonBlankDate )
    )



Regards,
Lydia

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

That worked like a charm. Thanks so much for suggesting. This really helps me! 🙂

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.