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
patrickbender
Helper I
Helper I

Get value of second table based on multiple conditions

Hi,

I have two tabels.

One with historic values of an asset and one with asset purchases.

I want to get the historic values of the asset purchases based on a what if parameter preferably using a measure.

 

For example if the what if parameter is 5 i would like to get the historic value 5 days earlier. Sometimes there won't be a historic value that specific date and then i would like to get the value of the first date before that date (for example 6 days earlier). 

 

Below are the structure of the tables.

Historic values table:

Asset ID

Date

Price

 

Asset purchases table:

Asset ID

Transaction date

Price

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Try

Historic price =
VAR WhatIf = [What if value]
RETURN
    SUMX (
        'Asset purchases',
        SELECTCOLUMNS (
            TOPN (
                1,
                FILTER (
                    'Historic values',
                    'Historic values'[Asset ID] = 'Asset purchases'[Asset ID]
                        && 'Historic values'[Date] <= 'Asset purchases'[Date] - WhatIf
                ),
                'Historic values'[Date]
            ),
            "@value", 'Historic values'[Price]
        )
    )

View solution in original post

2 REPLIES 2
patrickbender
Helper I
Helper I

Thanks 🙂

johnt75
Super User
Super User

Try

Historic price =
VAR WhatIf = [What if value]
RETURN
    SUMX (
        'Asset purchases',
        SELECTCOLUMNS (
            TOPN (
                1,
                FILTER (
                    'Historic values',
                    'Historic values'[Asset ID] = 'Asset purchases'[Asset ID]
                        && 'Historic values'[Date] <= 'Asset purchases'[Date] - WhatIf
                ),
                'Historic values'[Date]
            ),
            "@value", 'Historic values'[Price]
        )
    )

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.