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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mail2vjj
Helper III
Helper III

Compare value in 2 different tables and return result

Hi,

 

I have a problem for comparing numbers in a column to a limited set of numbers in a different table column and returning a result in a new column.

 

Please have a look at the tables below, then I will be able to describe my problem in a better way.

 

First table is the Sales table, which contains the employee ID and the Sales (which is a calculated column).

The second table is the Incentive table, which contains the Incentive slabs and the percentage of incentive.

 

Now I want to compute the incentive percentage based on the sales.

 

Sales Table

Employee IDSalesIncentive Earned
124764 
277984 
3103161 
463034 
5154584 
662805 
777631 
8122275 
9110846 
1069602 

 

Incentive Table

SLABS UPTOINCENTIVE %
649991.00%
900001.25%
1150002.00%
1400002.50%
1650003.00%
1950003.50%
2500004.00%
2750004.50%
2750015.00%

 

So for example, for Employee ID Number 2, the Sales is 77,984, so this is greater than 64,999 and less than 90,000( in the Incentive table, 'Slabs upto' column), so 'Incentive Earned' column in the Sales table should return the value 1.00%.

For Employee ID Number 5, the Sales is 154,584, so 'Incentive Earned' column shows 2.50%.

For Employee ID Number 1, the Sales is 24,764, so 'Incentive Earned' column shows 0%....so on and so forth.

 

Again, the Sales column in the Sales Table is a CALCULATED COLUMN and has more than 500 rows, which need to be compared the 'SLABS UPTO' column.

 

I have created a relationship between the 'Sales' [Sales] column and the 'Incentive' [Slabs up to] column and tried using the IF function and the RELATED function, which only works if the values are exactly the same, for eg. if sales column has 64999 then result is 1% but if sales is 65000, then it results a blank.

 

Sorry for posting too long a problem and I will be grateful if anyone can help me with the solution.

 

Thank you,

1 ACCEPTED SOLUTION
v-huizhn-msft
Employee
Employee

Hi @mail2vjj,
 

I have reproduce your scenario and get expected result. Please see the following solution step by step.


1. Create a calculate column to get the Max Incentive[SLABS UPTO] compared to Sales[Sales].

 

Column = CALCULATE(MAX(Incentive[SLABS UPTO]),FILTER(Incentive,Incentive[SLABS UPTO]<=Sales[Sales]))


2. Create another new table by clicking "New table" under Modeling on Home page.

Table = ALLSELECTED(Incentive)


1.PNG

3. Create a relationship between 'Table' and Sales table by SLABS UPTO.

2.PNG

4. Create another calculated column to get expected result.

Incentive Earned = IF(ISBLANK(RELATED('Table'[INCENTIVE %])),0,RELATED('Table'[INCENTIVE %]))



3.png

Best Regards,
Angelia


 

View solution in original post

4 REPLIES 4
v-huizhn-msft
Employee
Employee

Hi @mail2vjj,
 

I have reproduce your scenario and get expected result. Please see the following solution step by step.


1. Create a calculate column to get the Max Incentive[SLABS UPTO] compared to Sales[Sales].

 

Column = CALCULATE(MAX(Incentive[SLABS UPTO]),FILTER(Incentive,Incentive[SLABS UPTO]<=Sales[Sales]))


2. Create another new table by clicking "New table" under Modeling on Home page.

Table = ALLSELECTED(Incentive)


1.PNG

3. Create a relationship between 'Table' and Sales table by SLABS UPTO.

2.PNG

4. Create another calculated column to get expected result.

Incentive Earned = IF(ISBLANK(RELATED('Table'[INCENTIVE %])),0,RELATED('Table'[INCENTIVE %]))



3.png

Best Regards,
Angelia


 

Hi @v-huizhn-msft

 

First of all thank you for your reply, your solution worked and I got the desired result, but I had to tweak your solution a bit.

 

So now I have a couple of questions, if you would be so kind to please answer them for me.

 

I will show you what problem I faced and a minor tweak that worked, also I would really appreciate it if you could please explain to me the 2nd formula that you used and how does the function ISBLANK works.

 

1.

I tried to create a new table used the ALLSELECTED function and it gave me the same table with an extra row. I did check my excel file and there was no blank row in it and probably because of that it gave me an error when I tried to create a relationship between the 'Sales' [Column] and the 'Table' [Slabs Upto]. (For some reason I am unable to insert the screenshot).

 

So to solve this, I just created a new reference table from the Incentive table and got the realtionship.

 

2.

I tried using a simple IF function, without creating a new table, so why did that not work, since there is a relationship between the Sales table and the Incentive table.

 

 

Incentive Earned = IF ('Sales' [Column] = (Related('Incentive' [Slabs])), RELATED('Incentive'[Incentive %]),0))

 

......my parenthesis might be wrong.

 

Why did we have to create a whole new table and create a relationship?

 

3.

Can you please explain how does your formula work and how does ISBLANK work in this formula?

 

Incentive Earned = IF(ISBLANK(RELATED('Table'[INCENTIVE %])),0,RELATED('Table'[INCENTIVE %]))

 

As you might have figured it by now I am fairly new to Power BI and will really appreciate it if you could please help me with this.

 

Thank you so much for the solution.

Hi @mail2vjj,

1. Please Edit your resource table, and check if there is operation, please see the highlighted in red line.

1.PNG

2. If there is no relationship between two tables, the RELATED function can not be used. If we did not create new table, the relationship can not be created. Becasue the column come from the Incentive table, if create a relationship to Incentive, it's easily to recognize, just like create a relationship by myself.

3. 

Incentive Earned = IF(ISBLANK(RELATED('Table'[INCENTIVE %])),0,RELATED('Table'[INCENTIVE %]))


The ISBLANK function is used to judge if RELATED('Table'[INCENTIVE %] is blank. If it is blank, the logical_test return True, the result is 0. If the logical_test return False, the result is RELATED('Table'[INCENTIVE %].

In addition, please mark the reply as answer if it is helpful. Thanks a lot.

Best Regards,
Angelia

Hi @v-huizhn-msft,

 

Thank you for your reply, however I am still confused a bit.

 

For 1.

Yes, I checked my query and it does have the 'Changed type' step in the applied steps section.

Screenshot (5).png

The extra row in the new table with 'AllSelected' FunctionThe extra row in the new table with 'AllSelected' Function

 

For 2.

This is what I understood from your reply. We created a new table because without it, putting in the formulas would kind of become like a circular reference.

 

 

 

For 3.

Why are we checking if the Incentive % column is blank or not? The column is not blank so shouldn't it return the value false.

Also, instead of checking the incentive % column, shouldn't we check the new column that we created and use that to get the result in the Incentive earned column?

 

The new column named 'Column'The new column named 'Column'

 

Again, thank you for your solution, it works and gives me the desired result, but I am just trying to understand the logic behind it and where did I go wrong in my solution/modeling.

 

Thanks,

 

Vishesh

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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