cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SimoneWilk
Regular Visitor

New column returns value by looking up corresponding value from a date column + X Months

I have one table and I want to create a "New Value Column".

Each Unique Name has an "Original Month".

I want to add 36 months to the Original Month value, then look up the corresponding date from the "Lookup Month' column, then lookup the value from the "Original Value" column, and set that value as the new value  for "New Value Column" every time you see that Unique Name. 

If there is no "Original Month + 36 months", then set the "New Value Column" as null for that Unique Name.

 

Thank you for the help.

NameLookup MonthOriginal MonthOriginal Value New Value Column
John6/1/201711/20/2015118
John7/1/201711/20/2015218
John8/1/201711/20/2015318
John9/1/201711/20/2015418
John10/1/201711/20/2015518
John11/1/201711/20/2015618
John12/1/201711/20/2015718
John1/1/201811/20/2015818
John2/1/201811/20/2015918
John3/1/201811/20/20151018
John4/1/201811/20/20151118
John5/1/201811/20/20151218
John6/1/201811/20/20151318
John7/1/201811/20/20151418
John8/1/201811/20/20151518
John9/1/201811/20/20151618
John10/1/201811/20/20151718
John11/1/201811/20/20151818
Betty3/1/201811/28/20171null
Betty4/1/201811/28/20172null
Betty5/1/201811/28/20173null
Betty6/1/201811/28/20174null
Betty7/1/201811/28/20175null
Betty8/1/201811/28/20176null
Betty9/1/201811/28/20177null
Betty10/1/201811/28/20178null
Betty11/1/201811/28/20179null
Betty12/1/201811/28/201710null
Betty1/1/201911/28/201711null
Betty2/1/201911/28/201712null
Betty3/1/201911/28/201713null
Betty4/1/201911/28/201714null
Betty5/1/201911/28/201715null
Betty6/1/201911/28/201716null
Betty7/1/201911/28/201717null
1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @SimoneWilk ,

Please try below steps:

1. create a measure with below dax formula

Measure =
VAR cur_name =
    SELECTEDVALUE ( 'Table'[Name] )
VAR cur_om =
    SELECTEDVALUE ( 'Table'[Original Month] )
VAR cur_om_year =
    YEAR ( cur_om )
VAR cur_om_month =
    MONTH ( cur_om )
VAR tmp1 =
    FILTER ( ALL ( 'Table' ), 'Table'[Name] = cur_name )
VAR _val =
    CALCULATE (
        MAX ( [Original Value ] ),
        FILTER (
            tmp1,
            YEAR ( [Lookup Month] ) = cur_om_year + 3
                && MONTH ( [Lookup Month] ) = cur_om_month
        )
    )
RETURN
    IF ( ISBLANK ( _val ), "null", _val )

2. add a table visual with fields and measure

vbinbinyumsft_0-1669085629070.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
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

1 REPLY 1
v-binbinyu-msft
Community Support
Community Support

Hi @SimoneWilk ,

Please try below steps:

1. create a measure with below dax formula

Measure =
VAR cur_name =
    SELECTEDVALUE ( 'Table'[Name] )
VAR cur_om =
    SELECTEDVALUE ( 'Table'[Original Month] )
VAR cur_om_year =
    YEAR ( cur_om )
VAR cur_om_month =
    MONTH ( cur_om )
VAR tmp1 =
    FILTER ( ALL ( 'Table' ), 'Table'[Name] = cur_name )
VAR _val =
    CALCULATE (
        MAX ( [Original Value ] ),
        FILTER (
            tmp1,
            YEAR ( [Lookup Month] ) = cur_om_year + 3
                && MONTH ( [Lookup Month] ) = cur_om_month
        )
    )
RETURN
    IF ( ISBLANK ( _val ), "null", _val )

2. add a table visual with fields and measure

vbinbinyumsft_0-1669085629070.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.