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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
komaragiri
Regular Visitor

Lookup tables and calculate % value.

I have 2 tables.  

 

 

Vendor NameTotal Value
ABC10000
XYZ20000
ABCD50000
T2-VendorFrom ValueTo ValuePercentage
ABC050005%
ABC50011000010%
ABC1000110000020%
XYZ050005%
XYZ50011000010%
XYZ1000110000020%
ABCD010000015%
    

 

I need to Look Vendor name from Table 1 to Table 2.  Once I find the value, See if the Total Value from Table 1 falls in to which range to get the Percentage Value.   Store the Pecentage value on the Table 1 as column against each row.  

Need DAX formula for column creation. 

 

Final Results (Table 1, after adding colum pecentage)  

Vendor NameTotal ValuePercentageDiscount
ABC1000010%1000
XYZ2000020%4000
ABCD5000015%7500

Appreciate your help.  

 

2 ACCEPTED SOLUTIONS
some_bih
Super User
Super User

Hi @komaragiri create two columns in vendor table as

Value Percentage and Discount. Adjust your table names / columns accordingly and you should get Output

 

 

Value Percentage =
CALCULATE(
    MAX(Table2[Percentage]),
        FILTER(
        Table2,Table2[Vendor]=Vendor[Vendor Name] && Table2[From Value]<=Vendor[Total Value] && Table2[To Value]>=Vendor[Total Value]
        )
)
 
Discount = ROUND(Vendor[Total Value]*Vendor[Value Percentage],2)
 
Output
some_bih_0-1714716515530.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






View solution in original post

AntrikshSharma
Community Champion
Community Champion

@komaragiri You can build a relationship between 2 tables assuming the Table1 won't have duplicates in future.

AntrikshSharma_0-1714717080848.png

In Table1 you can create a the column using:

 

Discount = 
VAR T1_TotalValue = Table1[Total Value]
VAR T2_SameRows = 
    CALCULATETABLE ( 
        Table2,     
        T1_TotalValue >= Table2[From Value]
            && T1_TotalValue <= Table2[To Value] 
    )
VAR Result = 
    SUMX ( T2_SameRows, Table2[Percentage] * T1_TotalValue )
RETURN 
    Result

 

AntrikshSharma_1-1714717161612.png

 

You can also create the column in Table2 using:

 

Discount = 
VAR T1_TotalValue = 
    RELATED ( Table1[Total Value] )
VAR ValueInRange = 
    T1_TotalValue >= Table2[From Value]
        && T1_TotalValue <= Table2[To Value]
VAR Result = 
    ( Table2[Percentage] * T1_TotalValue ) * ( ValueInRange * 1 )
RETURN 
    Result

 

 

AntrikshSharma_2-1714717236183.png

 

 

 

View solution in original post

3 REPLIES 3
komaragiri
Regular Visitor

thank you for your solutions 

AntrikshSharma
Community Champion
Community Champion

@komaragiri You can build a relationship between 2 tables assuming the Table1 won't have duplicates in future.

AntrikshSharma_0-1714717080848.png

In Table1 you can create a the column using:

 

Discount = 
VAR T1_TotalValue = Table1[Total Value]
VAR T2_SameRows = 
    CALCULATETABLE ( 
        Table2,     
        T1_TotalValue >= Table2[From Value]
            && T1_TotalValue <= Table2[To Value] 
    )
VAR Result = 
    SUMX ( T2_SameRows, Table2[Percentage] * T1_TotalValue )
RETURN 
    Result

 

AntrikshSharma_1-1714717161612.png

 

You can also create the column in Table2 using:

 

Discount = 
VAR T1_TotalValue = 
    RELATED ( Table1[Total Value] )
VAR ValueInRange = 
    T1_TotalValue >= Table2[From Value]
        && T1_TotalValue <= Table2[To Value]
VAR Result = 
    ( Table2[Percentage] * T1_TotalValue ) * ( ValueInRange * 1 )
RETURN 
    Result

 

 

AntrikshSharma_2-1714717236183.png

 

 

 

some_bih
Super User
Super User

Hi @komaragiri create two columns in vendor table as

Value Percentage and Discount. Adjust your table names / columns accordingly and you should get Output

 

 

Value Percentage =
CALCULATE(
    MAX(Table2[Percentage]),
        FILTER(
        Table2,Table2[Vendor]=Vendor[Vendor Name] && Table2[From Value]<=Vendor[Total Value] && Table2[To Value]>=Vendor[Total Value]
        )
)
 
Discount = ROUND(Vendor[Total Value]*Vendor[Value Percentage],2)
 
Output
some_bih_0-1714716515530.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors