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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Harshc374
New Member

How to replace values based on another cell of another column

I have the below data with trade, stock and price column where the output price column should be 

 

If Trade= "BUY" then Price corresponding to BUY

Else if Trade= "SELL" then Price corresponding to BUY in all sell rows

 

So basically the output for all the trades should be the Price for BUY trade i.e. 2000 in our example

Screenshot_20240221_023447_Sheets.jpg

1 ACCEPTED SOLUTION
talespin
Solution Sage
Solution Sage

hi @Harshc374 

 

If you need it as a Calculated Column. In case there are multiple BUY, it will take MAX of that price, you can modify as per your requirement.

 

Output =
VAR _Stock = Stock[Stock]
VAR _BuyPrice = CALCULATE(MAX(Stock[Price]), REMOVEFILTERS(Stock), Stock[Stock] = _Stock && Stock[TRADE] = "BUY")
RETURN _BuyPrice
 
talespin_0-1708481406092.png

View solution in original post

2 REPLIES 2
talespin
Solution Sage
Solution Sage

hi @Harshc374 

 

If you need it as a Calculated Column. In case there are multiple BUY, it will take MAX of that price, you can modify as per your requirement.

 

Output =
VAR _Stock = Stock[Stock]
VAR _BuyPrice = CALCULATE(MAX(Stock[Price]), REMOVEFILTERS(Stock), Stock[Stock] = _Stock && Stock[TRADE] = "BUY")
RETURN _BuyPrice
 
talespin_0-1708481406092.png
Anonymous
Not applicable

Hi @Harshc374 

 

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Table"

vnuocmsft_0-1708479432266.png

 

Create a measure. Query the Price of Trade="BUY", and when Trade="SELL", output the Price of BUY.

 

Output Price = 
    VAR BUY_Price = 
        CALCULATE(
            VALUES('Table'[Price]), 
            FILTER(
                ALL('Table'), 
                'Table'[Stock] = MAX('Table'[Stock]) 
                && 
                'Table'[Trade] = "BUY"
            )
        )
RETURN 
    IF(
        SELECTEDVALUE('Table'[Trade]) = "BUY",
         VALUES('Table'[Price]),
        BUY_Price
    )

 

Here is the result.

 

vnuocmsft_1-1708479694401.png

 

Regards,

Nono Chen

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

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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