Forum Discussion
SCD (Type 2) for Profit calculation
- Anonymous2 years ago
Hi Dor-Y13 ,
1. Create Relationships: Ensure that there is a relationship between your `StockMoves` fact table and the `PricesforSCD` dimension table. The relationship should be based on the item identifier.
2. Create a Measure.
Gross Profit Measure = VAR SaleDate = MAX(StockMoves[SalesDate]) -- Replace with your actual sales date column VAR ItemID = MAX(StockMoves[ItemID]) -- Replace with your actual item identifier column VAR CostPrice = CALCULATE ( MAX(PricesforSCD[CostPrice]), -- Replace with your actual cost price column PricesforSCD[StartDate] <= SaleDate, PricesforSCD[EndDate] >= SaleDate, PricesforSCD[ItemID] = ItemID ) RETURN SUMX( StockMoves, (StockMoves[SalesAmount] - CostPrice) * StockMoves[Quantity] -- Replace with your actual sales amount and quantity columns )Please Note: The DAX provided is a basic template and might need to be adjusted based on the exact structure of your data model and business logic.
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Dor-Y13 ,
1. Create Relationships: Ensure that there is a relationship between your `StockMoves` fact table and the `PricesforSCD` dimension table. The relationship should be based on the item identifier.
2. Create a Measure.
Gross Profit Measure =
VAR SaleDate = MAX(StockMoves[SalesDate]) -- Replace with your actual sales date column
VAR ItemID = MAX(StockMoves[ItemID]) -- Replace with your actual item identifier column
VAR CostPrice =
CALCULATE (
MAX(PricesforSCD[CostPrice]), -- Replace with your actual cost price column
PricesforSCD[StartDate] <= SaleDate,
PricesforSCD[EndDate] >= SaleDate,
PricesforSCD[ItemID] = ItemID
)
RETURN
SUMX(
StockMoves,
(StockMoves[SalesAmount] - CostPrice) * StockMoves[Quantity] -- Replace with your actual sales amount and quantity columns
)
Please Note: The DAX provided is a basic template and might need to be adjusted based on the exact structure of your data model and business logic.
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Dor-Y132 years agoFrequent Visitor
Anonymous
Hi friend, could you please try to comment regard my reply?
Do you think it will be Better to try to add the cost price to the FACT table by using calculated column?
- Anonymous2 years agoNot applicable
Hi Dor-Y13 ,
What do you want to do with a null enddate? You can use the ISBLANK function in conjunction with the IF function within the measure to do something when the enddate is null.
I don't quite understand your logic here, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples.
Refer:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.