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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Stopira
Frequent Visitor

Syntax to find value

Hi Expert,

 

i am new to power BI, i decided to visit forum and ask for solution.

 

I have two tables.

The first 1 is transactions table

Transaction DateTransaction NumberCustomer Account
2/9/2020KK-09-0001KK-00001
10/9/2020KK-09-0002KK-00002
27/9/2020KK-09-0003KK-00003

 

The second is SalesLine Table

Transaction NumberItem IDItem nameCategoryAmount
KK-09-0001Product001Item AProduct     500,000.00
KK-09-0001Product002Bag                      -  
KK-09-0002Product003Item BProduct     200,000.00
KK-09-0002Product004Item CProduct     300,000.00
KK-09-0003Product005Item DProduct  1,000,000.00

What syntax do i need to use to get the category value to the transaction table. Because if i am using lookupvalue, it will return error.. Just need to get first value..

 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Stopira 

 

you can join both tables and transform the joined table (extracting first row of Category). Another approach could be to add a new column where filtering the other table and extract again first row of Category. Here an example code of the first approach

let
    TATable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtK31DcyMDJQ0lHy9tY1sNQ1MDAwhHLAzFidaCVDAyyqjBCqjMCqjMyxqDJGqDJWio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Transaction Date" = _t, #"Transaction Number" = _t, #"Customer Account" = _t]),
    SATable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8vbWNbDUNTAwMFTSUQooyk8pTS6BcDxLUnMVHBGiQJYCCJgaGOgA1esZGCjF6uAywAjIcUpMB+mB6UMHugoKqAYYIRtgDHOBE6YLjHC4AMUAE5gBzpgGGOMwwBjZAFOYAS5oBhiC9ML1xwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Transaction Number" = _t, #"Item ID" = _t, #"Item name" = _t, Category = _t, Amount = _t]),
    JoinTables = Table.NestedJoin
    (
        TATable, 
        "Transaction Number",
        SATable, 
        "Transaction Number",
        "SATable"
    ), 
    TransformJoinedTable = Table.TransformColumns
    (
        JoinTables,
        {
            {
                "SATable",
                (tbl)=> try tbl[Category]{0} otherwise null,
                type text
            }
        }
    )

in
    TransformJoinedTable

Jimmy801_0-1603782721639.png

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

Hello @Stopira 

 

you can join both tables and transform the joined table (extracting first row of Category). Another approach could be to add a new column where filtering the other table and extract again first row of Category. Here an example code of the first approach

let
    TATable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtK31DcyMDJQ0lHy9tY1sNQ1MDAwhHLAzFidaCVDAyyqjBCqjMCqjMyxqDJGqDJWio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Transaction Date" = _t, #"Transaction Number" = _t, #"Customer Account" = _t]),
    SATable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8vbWNbDUNTAwMFTSUQooyk8pTS6BcDxLUnMVHBGiQJYCCJgaGOgA1esZGCjF6uAywAjIcUpMB+mB6UMHugoKqAYYIRtgDHOBE6YLjHC4AMUAE5gBzpgGGOMwwBjZAFOYAS5oBhiC9ML1xwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Transaction Number" = _t, #"Item ID" = _t, #"Item name" = _t, Category = _t, Amount = _t]),
    JoinTables = Table.NestedJoin
    (
        TATable, 
        "Transaction Number",
        SATable, 
        "Transaction Number",
        "SATable"
    ), 
    TransformJoinedTable = Table.TransformColumns
    (
        JoinTables,
        {
            {
                "SATable",
                (tbl)=> try tbl[Category]{0} otherwise null,
                type text
            }
        }
    )

in
    TransformJoinedTable

Jimmy801_0-1603782721639.png

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

Thank you @Jimmy801

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.