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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Looking up values in another table with 2 parameters and no unique data or key

Hello,

 

I am brand new to Power BI with very limited knowledge in DAX, please be patient 🙂

 

I have two tables where I'm trying to pull values from one table to the other to perform a calculation. Both table 1 and table 2 have a date column and another column with values in common (but not unique, neither tables have keys or are unique).

 

Below is an example - please note that the Dollars (table 1) and Net (table 2) are aggregated/summed up and grouped - original data contains more details.

 

The desired output is a column that would act identically to an Excel lookup where it would look up the net in table 2 and returns it to table 1 for further calculation based on both the date and the lookup code. Even if new columns were to be added, the lookup would return identical values based on the 2 parameters.

 

I have attempted a join but it seems that Power BI doesn't allow for more than 1 active join.

 

Table 1 (Main table)

Lookup CodeIrrelevant Data ColumnDollars
ABCD5646541 $    1,323.00
ABCD3245361 $  87,689.00
ABCD6354 $  73,160.00
EFGH321 $    7,863.00
EFGH35435213 $  50,507.00
IJKL6354132 $  37,299.00
IJKL3541321 $  46,286.00
IJKL354321 $    5,081.00
IJKL3541 $  64,515.00
IJKL53 $  87,324.00

 

Table 2

LookupNet
ABCD50
EFGH25
IJKL250

 

Desired Output

Lookup CodeIrrelevant Data ColumnDollarsLookup Code 2 (identical to Excel vlookup)Dollars Div by Lookup Code 2
ABCD5646541 $    1,323.0050 $                                              26.46
ABCD3245361 $  87,689.0050 $                                        1,753.78
ABCD6354 $  73,160.0050 $                                        1,463.20
EFGH321 $    7,863.0025 $                                           314.52
EFGH35435213 $  50,507.0025 $                                        2,020.28
IJKL6354132 $  37,299.00250 $                                           149.20
IJKL3541321 $  46,286.00250 $                                           185.14
IJKL354321 $    5,081.00250 $                                              20.32
IJKL3541 $  64,515.00250 $                                           258.06
IJKL53 $  87,324.00250 $                                           349.30

 

Any help is appreciated.

 

Thank you,

Jake

1 ACCEPTED SOLUTION

hi, @Anonymous 

For you different, you have same lookup code, the relationship should be many to many.

And for date slicer from two tables, its type should be list, and create a column instead of measure. 

Notice:
1. Calculation column/table not support dynamic changed based on filter or slicer.
2. Measure can be affected by filter/slicer, so you can use it to get dynamic summary result.
here is reference:
https://community.powerbi.com/t5/Desktop/Different-between-calculated-column-and-measure-Using-SUM/t...
https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

3.JPG

 

Best Regards,
Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Thank you everyone for your support!

v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

you could try this simple way as below:

Step1:

Create a relationship between table1 and table2 by Lookup column and set cross filter direction is "Both"

Step2:

Use this formula to add a new column in table 1

Column = Table1[Dollars]/RELATED(Table2[Net])

or use this formula to add a new measure

Measure = SUMX(Table1,CALCULATE(SUM(Table1[Dollars]))/CALCULATE(SUM(Table2[Net])))

Result:

10.JPG

and here is pbix file, please try it.

 

Best Regards,
Lin

 

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-lili6-msft 

 

I looked at the file and it works. But for some reason when I try to apply th same relationship to my file I get the error "The cardinality you selected isn't valid for this relationship"04-05-2019 11-39-23 AM.png

 

It might be due to the date field. As I mentioned previously, there are date fields in the raw data that were not included in the original data set. Please see below for the tables with dates. I tried to do a relationship for both date and lookup fields but it wouldn't allow it. 

 

Table 1

Lookup CodeDateIrrelevant Data ColumnDollars

ABCD01/01/201856465411323
ABCD01/01/2018324536187689
ABCD01/01/2018635473160
EFGH01/01/20183217863
EFGH01/01/20183543521350507
IJKL01/01/2018635413237299
IJKL01/01/2018354132146286
IJKL01/01/20183543215081
IJKL01/01/2018354164515
IJKL01/01/20185387324
ABCD02/01/20185458995
ABCD02/01/20189684759465
ABCD02/01/201836514917664
EFGH02/01/2018968714643
EFGH02/01/2018635459661
IJKL02/01/20186416468
IJKL02/01/20186987472238
IJKL02/01/20183652151818
IJKL02/01/201832116266
IJKL02/01/201832126069

 

 

Table 2

LookupNetDate

ABCD5001/01/2018
EFGH2501/01/2018
IJKL25001/01/2018
ABCD5402/01/2018
EFGH3002/01/2018
IJKL26002/01/2018

 

Thank you,

Jake

 

hi, @Anonymous 

For you different, you have same lookup code, the relationship should be many to many.

And for date slicer from two tables, its type should be list, and create a column instead of measure. 

Notice:
1. Calculation column/table not support dynamic changed based on filter or slicer.
2. Measure can be affected by filter/slicer, so you can use it to get dynamic summary result.
here is reference:
https://community.powerbi.com/t5/Desktop/Different-between-calculated-column-and-measure-Using-SUM/t...
https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

3.JPG

 

Best Regards,
Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@Anonymous ,

First off, welcome to the wonderful and wonderfully aggravating world of PBI 🙂

 

Not sure if you are aware, but there's another tool in PBI which is Power Query.  You can use that to merge the lookup table into your maintable and then add a column to divide it out

 

1. Merge the MainTable with the Lookup table:

Initial Merge.png

Expand the Lookup Table to get the Net:

Expand out.png

 

Add a custom column

Custom Column.png

 

Final Table:

Final Table.png

Anonymous
Not applicable

Hi Nick,

 

Thank you for your reply, this is great but the issue is that when I pull this data into the main dashboard (not sure of terminology is correct) it sums up the Net. I was able to make the merge on both date and lookup code column but it pulls the sume into the dashboard table.

 

Is there a way to just copy the pre-aggregated value into the 1st table to apply the division or does it have to be done in Power Query? Please keep in mind that table 1 will have filters and columns will be added and removed constantly, the lookup needs to be the same value as in table 2.

 

Please see below:

powerbi_support.png

Current output with merged query:

current_output_power_bi.png

 

Anonymous
Not applicable

Sure, you can do this in DAX as well.  You can bring in the NET using lookup:

 

Net, Using LOOKUP = 
IF( 
    HASONEFILTER(Table2[Lookup]),
    LOOKUPVALUE( 
        Table2[Net], 
        Table2[Lookup], 
        VALUES(Table2[Lookup])
    )
)

Then you can divide that out:

 

 

Total Dollars = SUM ( Table1[Dollars] )

Total Dollars / Net = 
SUMX( 
    VALUES( Table2[Lookup] ), //SUMX and VALUES just ensures you get the correct grand total
    DIVIDE( [Total Dollars], [Net, Using LOOKUP])
)

Dax, Final Table.png

 

Use the LookUp column from Table2 on rows.  Since you should have a 1:M relationship with Table1, these rows will filter table1 to get you the correct total.  

 

You can add in Dates no problem, just increases the complexity a little bit, since you will have to add some sort of date logic to the lookup measure.  Which isnt terrible, assuming there are not any missing dates... but one step at a time 🙂

 

Anonymous
Not applicable

When I try that formula I get an empty column for some reason. I attempted to make some changes but getting the same issue. No error comes up but the column comes out empty.

 

Exact steps: Fields -> Right click on table -> New Column -> pasted formula -> added field to table

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.