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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
notski
Regular Visitor

Custom column calculation

Hey folks,

 

I'm fairly new to Power BI so I appreciate all the help I can get 🙂

 

I have two tables, one with a sales ledger (Sales) and the other containing product information (Products). Each row on Sales details the Date, Item Number, Sales Amount, Sales Quantity and Cost Amount, and the rows in Products contain Item Number and Unit Cost (among other things).

 

Due to issues with the ERP I'm working with, Cost Amounts for some transactions on the Sales table are outrageously wrong and can't be corrected in the source data, so I need to calculate a corrected cost amount for transactions which meet a certain criteria (let's assume Sales Amount - Cost Amount < 0). For transactions meeting the criteria, I need to fetch the Unit Cost from the Products table and multiply that by Sales Quantity. Transactions which don't meet the criteria should be left as they are.

 

What would be the best way to go about this? My initial idea was to create a custom column (let's call it Corrected Cost) on the Sales table which evaluates the criteria and either calculates a new cost or inputs the existing Cost Amount. I'm just not sure how to make it happen 😄

 

Thanks in advance!

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

The exact details are going to depend on your data. But, let's say that Sales and Product tables are related on ProductID. You could do something like this:

 

Column = IF(([Sale Amount]-[Cost Amount])>0,[Sale Amount],RELATED('Products'[Price]))

Something along those lines.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

The exact details are going to depend on your data. But, let's say that Sales and Product tables are related on ProductID. You could do something like this:

 

Column = IF(([Sale Amount]-[Cost Amount])>0,[Sale Amount],RELATED('Products'[Price]))

Something along those lines.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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