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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
randeep
Helper I
Helper I

Conditional join on multiple columns

I have following model, which are imported into my project.

 

image.png

 

I would like to either have COGS field from Stock On Hand into Net Forecast or vice versa, by connecting product and date fields.

The idea is to calculate a new measure which is [Net Forecast].COGS / [Stock On Hand].COGS

In SQL, the query will look something like : 

select SOH.Product, SOH.Location, SOH.Date, SOH.QUANTITY AS SOH_QTY, F.QUANTITY AS FORECAST_QUANTITY from  bi.StockOnHand SOH 
FULL OUTER JOIN bi.NetForecastFile F 
ON SOH.Product = F.Product  AND SOH.Location = F.Location AND SOH.Date = F.Date
WHERE SOH.Quantity >0

 

Since both models are already imported, and huge, I would like to eliminate importing another model from query.

Rather have a table extracted from these model or DAX query. This is what I created so far, but end up with lots of empty rows and duplication.

StockTurnAround = 
Var MergeTable = GENERATEALL('bi StockOnHand', SELECTCOLUMNS(FILTER('bi NetForecastFile', 'bi NetForecastFile'[ConsolidateKey] = 'bi StockOnHand'[ConsolidateKey] && 'bi NetForecastFile'[Date] = 'bi StockOnHand'[Date]), "N.Product", 'bi StockOnHand'[Product], "N.Location", 'bi StockOnHand'[Location], "N.Date", 'bi StockOnHand'[Date], "SOH COGS", 'bi StockOnHand'[$COGS], "Forecast COGS", 'bi NetForecastFile'[$COGS]))
VAR MERGE_CLEAN_DISTINCT =
    DISTINCT ( MergeTable )
RETURN
MERGE_CLEAN_DISTINCT


Where am I getting the query wrong?

6 REPLIES 6
randeep
Helper I
Helper I

Turns out, simple LOOKUPVALUE was sufficient here.

LOOKUPVALUE('bi NetForecastFile'[$COGS],'bi NetForecastFile'[ConsolidateKey], 'bi StockOnHand'[ConsolidateKey], 'bi NetForecastFile'[Date], 'bi StockOnHand'[Date])

 

amitchandak
Super User
Super User

@randeep , As long as you have common dimensions like product and Date and Facts like Stock on Hand and net forecast join to those as shown in the relationship in power BI,

 

You can create a new measure

New measure = divide(sum('Net Forecast'[COGS]) ,sum('Stock On Hand'[COGS]))

 

and should able analyze that across Product and dates and any other common dimension

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  I wish it was that easy. 😀
You see there is no direct relationship established in between Net Forecast and Stock On Hand table. There is intermediarry table here, which is required too.

@randeep , you do not have a stock status table?

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Yes, but the relationship between Stock Status and Net Forecast on Product field. And Stock Status and Stock On Hand on Product field.

The Date field is connected to Calendar table.

When I use you proposed formula, it just sums up entire table. 

Greg_Deckler
Community Champion
Community Champion

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors