The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hello everyone,
Im kinda new to the DAX and im struggleing to calculate the final cost price of a product based on some variables.
What i have fixed is following:
The requirement is: if there is no value in the column Ending Date (see image below) then use the variable FinalCostPriceWithoutDate , otherwise use the variable FinalCostPriceWithDate .
My question is how to return the correct value (based on the underneath Dax) if there is no data in a column Ending Date (see image below) I think the part of Var NoDate and my Return statement is not correct. Please help.
Kind regards
Totaal CostPrice Products =
VAR Date =
MAX ( Fact_ValueEntry[PostingDate] )
VAR NoDate =
MIN (Dim_PurchasePrice[EndingDate])
VAR Product =
MAX ( Fact_ValueEntry[ItemFK] )
VAR CostPriceWithDate =
CALCULATE (
MAX ( Dim_PurchasePrice[DirectUnitCost] ),
Dim_PurchasePrice[ItemFK] = Product,
Dim_PurchasePrice[StartingDate] < Date,
Dim_PurchasePrice[EndingDate] >= Date
)
VAR CostPriceWithoutDate =
CALCULATE (
MAX ( Dim_PurchasePrice[DirectUnitCost] ),
Dim_PurchasePrice[ItemFK] = Product,
Dim_PurchasePrice[StartingDate] < Date,
Dim_PurchasePrice[EndingDate] = NoDate)
VAR CostPriceInk =
CALCULATE (
max ( Dim_PurchasePrice[DirectUnitCost] ),
Dim_PurchasePrice[ItemFK] = "INK")
VAR CostPriceGlue =
CALCULATE (
max ( Dim_PurchasePrice[DirectUnitCost] ),
Dim_PurchasePrice[ItemFK] = "GLUE")
VAR FinalCostPriceWithDate = CostPriceWithDate + CostPriceInk + CostPriceGlue
VAR FinalCostPriceWithoutDate = CostPriceWithoutDate + CostPriceInk + CostPriceGlue
RETURN
IF(ISBLANK(NoDate), FinalCostPriceWithoutDate, FinalCostPriceWithDate))
Solved! Go to Solution.
Hi @rsanyoto ,
Very happy about your feedback.
If the problem has been solved, you can mark the correct response as the standard answer to help the other members find it more quickly. Looking forward to your reply.
Best Regards,
Henry
Can you provide a test pbix please because it's a bit difficult to debug this without seeing the model/relationships?
Just fake a small example (and provide the desired result please) and link it from an external site and I'll have a look for you
Hi @HotChilli ,
I have uploaded the pbix example in my public github repository. Download the file of 2,19 mb
Please try this link:
https://github.com/regazzi24/powerbi/blob/main/Example%2011102021%20v1.pbix
User | Count |
---|---|
86 | |
84 | |
36 | |
34 | |
34 |
User | Count |
---|---|
94 | |
79 | |
65 | |
55 | |
52 |