cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
userdata
Helper IV
Helper IV

How to lookupvalue in second table where text value picks earlier date that is not null

Table 1                                                                          Table 2

date |  mean                                                                  date | std

27.4     34                                                                        24.4    c

12.3     12                                                                        12.3   blank

                                                                                         10.3 x

                                                                                           9.3  b

 

 

 

output i want to see:

 

date |  mean  | std                                                                

27.4     34        c                                                               

12.3     12        x

 

there are two different table 1 and 2 and what i need to do is lookup if date in first table is 12.3 then i need to check in table 2 if there is a std for 12.3 if not i have to take the latest value that is not blank, in this case it would be x.

How would I do that in DAX

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

Hi @userdata ,

 

I created two tables the same as you.

 

Table1:

vyadongfmsft_0-1659694840315.png

 

Table2:

vyadongfmsft_1-1659694840316.png

 

Please create a new column and try following DAX:

std = 
VAR lookup = LOOKUPVALUE('table2'[std],'table2'[date],'table1'[date])
RETURN
IF(
    NOT ISBLANK(lookup),lookup,
    MAXX(
        FILTER('table2','table2'[date]),
        'table2'[std])
        )

 

Then you can get result you want.

vyadongfmsft_2-1659694840318.png

 

Best Regards,

Yadong Fang

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

5 REPLIES 5
v-yadongf-msft
Community Support
Community Support

Hi @userdata ,

 

I created two tables the same as you.

 

Table1:

vyadongfmsft_0-1659694840315.png

 

Table2:

vyadongfmsft_1-1659694840316.png

 

Please create a new column and try following DAX:

std = 
VAR lookup = LOOKUPVALUE('table2'[std],'table2'[date],'table1'[date])
RETURN
IF(
    NOT ISBLANK(lookup),lookup,
    MAXX(
        FILTER('table2','table2'[date]),
        'table2'[std])
        )

 

Then you can get result you want.

vyadongfmsft_2-1659694840318.png

 

Best Regards,

Yadong Fang

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

@v-yadongf-msft Thanks so much for this!! You are a herooo!

userdata
Helper IV
Helper IV

@amitchandak  thanks for this . I tried to use the calculated column but I get the same value for std but it should change based on date.  The values do not show correctly

userdata_0-1659549602852.png

 

Anyone else who can help on this? How do I create a lookup for the latest date that is not null from table 2? Thanks!

amitchandak
Super User
Super User

@userdata , New column in table one

 

col  =

var _min = minx(filter(Table2, table2[Date] <= table1[Date]) , Table2[Date])

return

minx(filter(Table2, table2[Date] =_min) , Table2[std])



Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || Learn 50+ Power Query List Functions
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!!! How to get Quick Help !!
Resources | Master Power BI !! Expertise Power BI !! Power BI For Tableau User !!

Helpful resources

Announcements
collabdays lisbon

CollabDays Lisbon - 26 November 2022

Sessions include practical, hands-on experience that will help you take the next step in your career and know-how.

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.