Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Calculated Column - Receive Value Based on Nearest Date

Hi, 

 

I'm trying to create a calculated column from a second table based on a date value. The goal is to display the actual level for each account before a campaign has been send. 

 

Levels

AccountIDPrevFunnelLvlNewFunnelLvlChangeDate
101-L102.01.2022
101L1L206.01.2022
101L2L310.01.2022
202L2L308.01.2022
202L4L512.01.2022

 

Campaign

AccountIDCampaignDateLvlonCampaignDate
10105.01.2022L1
10111.01.2022L3
20210.01.2022L3

 

Thanks in advance!

4 Replies

  • Hi,

    I assume your two tables do not have a Many-to-Many relationship on the AccountID column?

    Level on Campaign Date =
    VAR AccountID = Campaign[AccountID]
    VAR CampaignDate = Campaign[CampaignDate]
    RETURN
        CALCULATE(
            MAX( 'Levels'[NewFunnelLevel] ),
            FILTER(
                'Levels',
                'Levels'[AccountID] = AccountID
                    && 'Levels'[ChangeDate] <= CampaignDate
            )
        )

    Regards

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      They do have an inactive many-to-many relationship but also connected via Account table. Sadly I didn't got %100 correct values on all rows.  

  • Perhaps post a new small example dataset and highlight the results from my formula which aren't correct.

    Regards

  • Hi Anonymous ,

     

    Sorry for that the information you have provided is not making the problem clear to me. Could you please share more details to help us clarify your scenario?

    Please provide us with more details about your table and your problem or share me with your pbix file after removing sensitive data.

    Refer to:

    How to provide sample data in the Power BI Forum

    How to Get Your Question Answered Quickly

     

    Best Regards,

    Jianbo Li

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.