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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
fabiomanniti
Helper III
Helper III

Lookup a value in same table different column

Hello, I have a table with contracts details.

Any contract has an ID and a Issue date.

It might happens when a contract expires the customer wants to renew it so it changes ID.  

For this reason I have a table like this

Current_IDOld_IDIssue_dateexpiration_date

 

I would like to check how many contracts expired on September has not been renewd.

In order to get this, I need to know how many "current_id" are not in the column "old_id".

 

I tried with the LOOKUPVALUE but I get an error

has_been_renewed = LOOKUPVALUE(Contracts[Current_id],Contracts[Old_ID],Contracts[Current_id]))

 

May somebody help me with this?
Thank you

 

 

 

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

Hi, @fabiomanniti 

 

vjaneygmsft_0-1639389502040.png

When the lookupvalue function is used in the measure, the column name can't be used directly in the red line part, but the aggregated value can be used. And you can extend the measure to filter the data for September.

vjaneygmsft_1-1639389530413.png

Reference:LOOKUPVALUE function (DAX) - DAX | Microsoft Docs

According to your description, I create a sample. If you want to dynamically select the month, you can create a new date column for filtering. Then create two measures, one for display matching rows, one for count.

vjaneygmsft_0-1639388314129.png

Table = CALENDARAUTO()
has_been_renewed 2 = 
CALCULATE (
    LOOKUPVALUE (
        Contracts[Current_ID],
        Contracts[Old_ID], MAX ( Contracts[Current_ID] )
    ),
    Contracts[expiration_date] in DISTINCT('Table'[Date])
)
count_has_been_renewed = 
COUNTX (
    ADDCOLUMNS (
        Contracts,
        "a",
            CALCULATE (
                LOOKUPVALUE (
                    Contracts[Current_ID],
                    Contracts[Old_ID], MAX ( Contracts[Current_ID] )
                ),
                Contracts[expiration_date] IN DISTINCT ( 'Table'[Date] )
            )
    ),
    IF ( NOT ( ISBLANK ( [a] ) ), [a] )
)

vjaneygmsft_2-1639389821637.png

PBIX file sample is below.

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

View solution in original post

2 REPLIES 2
v-janeyg-msft
Community Support
Community Support

Hi, @fabiomanniti 

 

vjaneygmsft_0-1639389502040.png

When the lookupvalue function is used in the measure, the column name can't be used directly in the red line part, but the aggregated value can be used. And you can extend the measure to filter the data for September.

vjaneygmsft_1-1639389530413.png

Reference:LOOKUPVALUE function (DAX) - DAX | Microsoft Docs

According to your description, I create a sample. If you want to dynamically select the month, you can create a new date column for filtering. Then create two measures, one for display matching rows, one for count.

vjaneygmsft_0-1639388314129.png

Table = CALENDARAUTO()
has_been_renewed 2 = 
CALCULATE (
    LOOKUPVALUE (
        Contracts[Current_ID],
        Contracts[Old_ID], MAX ( Contracts[Current_ID] )
    ),
    Contracts[expiration_date] in DISTINCT('Table'[Date])
)
count_has_been_renewed = 
COUNTX (
    ADDCOLUMNS (
        Contracts,
        "a",
            CALCULATE (
                LOOKUPVALUE (
                    Contracts[Current_ID],
                    Contracts[Old_ID], MAX ( Contracts[Current_ID] )
                ),
                Contracts[expiration_date] IN DISTINCT ( 'Table'[Date] )
            )
    ),
    IF ( NOT ( ISBLANK ( [a] ) ), [a] )
)

vjaneygmsft_2-1639389821637.png

PBIX file sample is below.

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

amitchandak
Super User
Super User

@fabiomanniti , I think you need a measure for that, either sep is selected as date or we can assume static

 

Plot this against Current_ID

 

Measure =
var _date = date(2021,09,30)
var _exp = summarize(filter(Table, eomonth(Table[expiration_date],0) =_date),[Current_ID])
return
if( isblank(countrows(filter(Table , Table[Old] in _exp && Table[expiration_date] >_date))) && not(isblank( countrows(filter(Table , Table[Current_ID] in _exp && Table[expiration_date] <=_date) ))) ,[Current_ID] , blank())

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.