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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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