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

Investment Return Calculation - User Defined Start and End Dates

Hello, I have a Power BI data table called Investments which has three columns of data; Date, Investment and Price.  The table has time series price data on a dozen different investments.

 

I would like to be able to choose a start date and an end date using the Date Filter and to also choose one of the dozen investments also using a Filter, and for Power BI to calculate the investments return.

The example data below is for one investment.

DateInvestmentPrice
31/07/2015Basic Materials5417.11
31/08/2015Basic Materials5115.12
30/09/2015Basic Materials4739.60
30/10/2015Basic Materials5346.69
30/11/2015Basic Materials5444.16
31/12/2015Basic Materials5199.55
29/01/2016Basic Materials4683.97
29/02/2016Basic Materials4986.52
31/03/2016Basic Materials5454.90
29/04/2016Basic Materials5731.86
31/05/2016Basic Materials5724.49
30/06/2016Basic Materials5686.19
29/07/2016Basic Materials5999.92
31/08/2016Basic Materials5960.60
30/09/2016Basic Materials5900.81
31/10/2016Basic Materials5772.33
30/11/2016Basic Materials6248.61
30/12/2016Basic Materials6236.75

 

Thank you for any assistance.

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @pgree,

 

Firstly, you need a Calendar table. You could create with Calculated Table.

calendar = CALENDAR(MIN(Investments[Date]),MAX(Investments[Date]))

 

Then, you need a Measure.

calculated investment =
VAR startDate =
    MIN ( 'calendar'[Date] )
VAR endDate =
    MAX ( 'calendar'[Date] )
RETURN
    CALCULATE (
        SUM ( Investments[Price] ),
        FILTER (
            Investments,
            Investments[Investment] = SELECTEDVALUE ( Investments[Investment] )
                && Investments[Date] >= startDate
                && Investments[Date] <= endDate
        )
    )

 

The result looks like this.

vcazhengmsft_0-1662364079353.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

View solution in original post

1 REPLY 1
v-cazheng-msft
Community Support
Community Support

Hi @pgree,

 

Firstly, you need a Calendar table. You could create with Calculated Table.

calendar = CALENDAR(MIN(Investments[Date]),MAX(Investments[Date]))

 

Then, you need a Measure.

calculated investment =
VAR startDate =
    MIN ( 'calendar'[Date] )
VAR endDate =
    MAX ( 'calendar'[Date] )
RETURN
    CALCULATE (
        SUM ( Investments[Price] ),
        FILTER (
            Investments,
            Investments[Investment] = SELECTEDVALUE ( Investments[Investment] )
                && Investments[Date] >= startDate
                && Investments[Date] <= endDate
        )
    )

 

The result looks like this.

vcazhengmsft_0-1662364079353.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

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.

Top Solution Authors