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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
k33fun
Frequent Visitor

Lookup % Rebate on another table based on Invoice quantity

Hi,


I want to get the correct % Rebate from table A into table B based on the Invoice Qty of each Customer. 

How can I get it done via power query?

Table A

k33fun_1-1667894173203.png

 

Table B

k33fun_2-1667894356501.png

 

 

12 REPLIES 12
kirete17
Frequent Visitor

 

try this

Custom1 = 
        Table.AddColumn(
            Data,
            "Rebate",
            each
                List.Select( 
                    Table.ToRows( Table.ReverseRows( Rebate ) ), 
                    (x)=> x{0} = [Year Channel] and x{1} <= [Invoice Qty] 
                ){0}?{2}? ?? 0
        )

Hi Kirete,

 

Still get the same result, duplicating the records for each customer code with different %Rebate

wdx223_Daniel
Super User
Super User

NewStep=let a=Table.Buffer(Table.Group(TableA,"Key",{"n",Table.ToRows})) in Table.AddColumn(TableB,"%Rebate",each let lst=a{[Key=[Year_Chaneel]]}?[n]? in if lst=null then 0 else List.Last(List.RemoveLastN(lst,(x)=>x{1}>[Invoice Qty]),{}){2}? ??0)

Hi Daniel,

 

Thanks for your reply.

However based on your formula each Customer Code got duplicate into many lines with different %Rebate

k33fun_0-1667953560989.png

 

NewStep=let a=Table.Buffer(Table.Group(TableA,"Key",{"n",each Table.ToRows(Table.Sort(_,"Min"))})) in Table.AddColumn(TableB,"%Rebate",each let lst=a{[Key=[Year_Chaneel]]}?[n]? in if lst=null then 0 else List.Last(List.RemoveLastN(lst,(x)=>x{1}>[Invoice Qty]),{}){2}? ??0)

Hi Daniel,

 

Table A = CTC_Rule
Table B = Cognos_Total_Pivot 

 

Below error message appear

k33fun_1-1667963652570.png

 

 

wdx223_Daniel_0-1667965551578.png

 

try to delete those code

origin is like this but after save it show me that error message

k33fun_0-1667966179340.png

 

no need open this windows, jut put those code in the editor pane which is after "fx" lable

OK i got it but still appear the same error

 

k33fun_0-1667970862635.png

 

what's the relationship between those two tables? does one table comes from the other?

It is a many to many relationship between these 2 tables applied. 

 

k33fun_1-1667976482394.png

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.