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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Oomsen
Helper III
Helper III

Lookup within table

I'm using a tabl with items. 

For demonstration reasons we copied item codes and added "-demo".

The value of demo item is 0 for accounting reasons, so the cost price is €0. But the product itself does have a value. 

For example item 10.143 has a cost price of € 2700 (code and costprice column in the table).

I would like to add a custom column which generates the costprice for 10.143-demo.

My idea is to create a lookup for items with demo in the code. 

In that case item 10.143-demo suppost to get the cost price of item 10.143.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Oomsen ,

You can create a calculated column as below, please find the details in the attachment.

Column = 
VAR _position =
    IFERROR ( SEARCH ( "-Demo", 'Table'[code], 1, 0 ), 0 )
VAR _curcode = 'Table'[code]
RETURN
    IF (
        _position = 0,
        'Table'[costpricestandard],
        CALCULATE (
            MAX ( 'Table'[costpricestandard] ),
            FILTER ( ALL ( 'Table' ), LEFT ( _curcode, _position - 1 ) = 'Table'[code] )
        )
    )

yingyinr_0-1648710596562.png

Best Regards

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Oomsen ,

You can create a calculated column as below, please find the details in the attachment.

Column = 
VAR _position =
    IFERROR ( SEARCH ( "-Demo", 'Table'[code], 1, 0 ), 0 )
VAR _curcode = 'Table'[code]
RETURN
    IF (
        _position = 0,
        'Table'[costpricestandard],
        CALCULATE (
            MAX ( 'Table'[costpricestandard] ),
            FILTER ( ALL ( 'Table' ), LEFT ( _curcode, _position - 1 ) = 'Table'[code] )
        )
    )

yingyinr_0-1648710596562.png

Best Regards

Thanks, this is perfect!

amitchandak
Super User
Super User

@Oomsen , Not very clear

 

You can append and create in DAX and you need convert Number to text in case of power Query

 

Power query

"Demo-" & Number.ToText([Cost])

 

 

The information you have provided is not making the problem clear to me. Can you please explain with an example.

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
Appreciate your Kudos.

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

@amitchandak see the example below. 
I would like to get the 2700 for12.042-demo in a new column.

 

codecostpricestandarddescriptionenddateidisondemanditemispurchaseitemissalesitemisserialitemisstockitemitemgroupcodeitemgroupdescriptionstartdatestock
12.042-Demo0Left drive 70Vdc PU-air tires assemblynull4C493AE1-EAA2-4464-AA0F-3D581FF152E30FALSETRUEFALSETRUEDEDemo Robots01/10/2020 00:00:001
12.0422700Left drive 70Vdc PU-air tires assemblynullB802F624-B442-4B3E-8D05-43B38F7ABA6C1FALSETRUEFALSETRUEASAssemblies01/11/2014 00:00:000

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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