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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jasonminhas
Frequent Visitor

Trying to Create Column Using Data From Other Tables

My objective is to create a custom column in the Account Table that identifies whether the account has purchased the "New", "Old", "both Old and New", or "Not Old and New" products based on the "Product Tag" column in the Product Table. Below I have created the expected outcome I'm looking for in the Expected Outcome column of the Account Table. How can I create a calculated column in the Account Table to do this?

 

Here's a link to the .PBIX file: Sample Power BI Model.pbix

 

Account Table

Account IDAccount NameAddressExpected Outcome
100CareerBikeStreet DSGSOld and New
200BluckBikeStreet HJGOld
300EverBikeStreet TFGDNew
400BikeyStreet CVBBNot Old or New

 

Product Table

Product IDProduct GroupsCostProduct Tag
Product AGroup 1120Old
Product BGroup 1140Old
Product CGroup 1150Old
Product DGroup 2170New
Product EGroup 2180New
Product FGroup 2190New
Product GGroup 3125 
Product HGroup 4115 

 

Sales Table

Sales IDAccount IDProduct IDQuantityPurchase Date
100100Product A103/12/2022
200200Product B102/08/2022
300300Product H104/02/2022
400400Product H104/03/2022
500100Product D101/01/2022
600200Product G102/15/2022
700300Product E103/07/2022
800400Product G103/07/2022
1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Try this measure:

 

Product Tags by Account =
VAR Products =
    CALCULATETABLE (
        VALUES ( sales_table[Product ID] ),
        RELATEDTABLE ( sales_table )
    )
VAR PT =
    INTERSECT ( VALUES ( product_table[Product ID] ), Products )
VAR Tags =
    CALCULATETABLE ( VALUES ( product_table[Product Tag] ), PT )
VAR Ref = { "New", "Old" }
RETURN
    SWITCH (
        TRUE (),
        COUNTROWS ( INTERSECT ( Tags, ref ) ) > 1, CONCATENATEX ( Tags, product_table[Product Tag], " and " ),
        COUNTROWS ( INTERSECT ( Tags, ref ) ) = 1, CONCATENATEX ( Tags, product_table[Product Tag] ),
        "Not Old or New"
    )

 

 

Result.png

The code also works in a calculated column if you prefer

calccolumn.png

 

 I've attached the sample PBIX for you





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

2 REPLIES 2
rohit_singh
Solution Sage
Solution Sage

Hi @jasonminhas ,

Please try the following :

1)In the report view, ensure you have the following relationships created 

rohit_singh_0-1652719861859.png

rohit_singh_1-1652719882979.png

2) Navigate to the sales table and create a calulated column to lookup tag values from the product table

 
Prod Tag = Related(Model_Product[Product Tag])

rohit_singh_2-1652719955797.png

3) Create a calculated table from the sales table that has account id, and concatenated values of product tags in a single row. This is to ensure 1 row per account id

Sales Tag =

SUMMARIZE(
Model_Sales,
Model_Sales[Account ID],
"Tags", CONCATENATEX(VALUES(Model_Sales[Prod Tag]), Model_Sales[Prod Tag], ",")
)
 

rohit_singh_3-1652720045638.png

4) Create a calculated column on the new table to assign tags as per requirement. 

 

Tag Desc =

if('Sales Tag'[Tags] = "Old,New", "Old and New",
if('Sales Tag'[Tags] = "Old,", "Old",
if('Sales Tag'[Tags] = ",New", "New",
if('Sales Tag'[Tags] = BLANK(), "Not Old or New",
BLANK()))))

rohit_singh_5-1652720176946.png


5) Create a relationship between the accounts table and the new calculated table 

rohit_singh_4-1652720126407.png


6) Finally, add a calculated column to lookup tag values from the new table.

 

Tag = related('Sales Tag'[Tag Desc])

rohit_singh_6-1652720251058.png


This should give you the desired output.


Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊

PaulDBrown
Community Champion
Community Champion

Try this measure:

 

Product Tags by Account =
VAR Products =
    CALCULATETABLE (
        VALUES ( sales_table[Product ID] ),
        RELATEDTABLE ( sales_table )
    )
VAR PT =
    INTERSECT ( VALUES ( product_table[Product ID] ), Products )
VAR Tags =
    CALCULATETABLE ( VALUES ( product_table[Product Tag] ), PT )
VAR Ref = { "New", "Old" }
RETURN
    SWITCH (
        TRUE (),
        COUNTROWS ( INTERSECT ( Tags, ref ) ) > 1, CONCATENATEX ( Tags, product_table[Product Tag], " and " ),
        COUNTROWS ( INTERSECT ( Tags, ref ) ) = 1, CONCATENATEX ( Tags, product_table[Product Tag] ),
        "Not Old or New"
    )

 

 

Result.png

The code also works in a calculated column if you prefer

calccolumn.png

 

 I've attached the sample PBIX for you





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.