Forum Discussion

david_flu's avatar
david_flu
Frequent Visitor
2 years ago
Solved

how can i write the Lookup functions please

Hello   Could i please get some help with the below tables please. I'm trying to add a column which shows the total sale amount for each product / each region / each week. is there a way to do it ?...
  • danextian's avatar
    2 years ago

    Hi david_flu 

    You did not mention how to calcualte the sales amount but I am assuming it is unit price * kg. If so, try this calc column in your first table:

    Sales =
    VAR __UNIT_PRICE =
        LOOKUPVALUE (
            'table2'[Unit Price],
            'table2'[Regions], 'table1'[Store],
            'table2'[Product], 'table1'[Regions]
        )
    RETURN
        __UNIT_PRICE * 'Table1'[KGs]
    

    If this isn't what you're looking for, please elaborate your use case and provide a sample data we can easily copy-paste (not an image) as well as your sample result.  Please refer to this sticky post when creating new posts in the future: https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/3332479#M1112153 

  • parry2k's avatar
    2 years ago

    Daniel_PowerBI the solution danextian should work and you can also do this:

     

    add 2 new columns in each table and then set the relationship on these new columns, which will be one to many, one will be on the store/product side table. 

     

    //add new column in Sales Table
    Surrogate Key = SalesTable[Store] & SalesTable[Product]
    
    //add new column in Store Product table
    Surrogate Key = StoreProductTable[Store] & StoreProductTable[Product]
    
    //add new measure for sales
    Sales Measure = 
    SUMX (  SalesTable, SalesTable[Product Sales] & RELATED ( StoreProductTable[Unit Price] ) )

     

    and to visualize. use Week/Day/Store column from SalesTable and the measure Sales Measure

     

    Change the column names and table names as per your data model.