Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi All,
I am trying to find latest cost for each product. If we dont have Unit cost for a particular month I want the latest cost for each product. Like we dont have cost for product A for month 202103 hence we need cost for Product A for month 202102
Input:
Sales:
Product | MonthYear | Unit Sales |
A | 202105 | 100 |
A | 202104 | 120 |
A | 202103 | 130 |
Cost Data:
Product | MonthYear | UnitCost |
A | 202105 | 95 |
A | 202104 | 100 |
A | 202102 | 125 |
Output:
Product | MonthYear | Unit Sales | Unit Cost |
A | 202105 | 100 | 95 |
A | 202104 | 120 | 100 |
A | 202103 | 130 | 125 |
Solved! Go to Solution.
Hi, @AdityaPowerBI
Thanks for your feedback, and check the below.
Unit Cost CC =
VAR currentmonthyear = Sales[MonthYear]
VAR maxorcurrentmonthyearincosttable =
MAXX (
FILTER ( Costs, Costs[MonthYear] <= currentmonthyear ),
Costs[MonthYear]
)
RETURN
CALCULATE (
SUM ( Costs[Unit Cost] ),
FILTER ( Costs, Costs[MonthYear] = maxorcurrentmonthyearincosttable )
)
https://www.dropbox.com/s/s7vxjdkmbqlnti2/aditya.pbix?dl=0
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
@Jihwan_Kim Thanks for your solution. It is good but actually I am trying to get the cost as a column in Sales table. I want the cost value for each and every sales row
Hi, @AdityaPowerBI
Thanks for your feedback, and check the below.
Unit Cost CC =
VAR currentmonthyear = Sales[MonthYear]
VAR maxorcurrentmonthyearincosttable =
MAXX (
FILTER ( Costs, Costs[MonthYear] <= currentmonthyear ),
Costs[MonthYear]
)
RETURN
CALCULATE (
SUM ( Costs[Unit Cost] ),
FILTER ( Costs, Costs[MonthYear] = maxorcurrentmonthyearincosttable )
)
https://www.dropbox.com/s/s7vxjdkmbqlnti2/aditya.pbix?dl=0
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
@Jihwan_KimThanks again for the response. When I am implementing your logic, the problem I am facing is maxorcurrentmonthyearincosttable is fetching me exact same month year as present in sales instead of bringing last available. Is there any kind of messaging or calling medium where I can explain you the issue?
Hi, @AdityaPowerBI
Thanks for the feedback.
Share your sample pbix file's link here, then I can try to look into it.
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi @Jihwan_Kim I got it fixed finally. The issue with the current logic was it was not filtering for the product in filter condition in maxorcurrentmonthyearincosttable variable. I have added a condition of comparing product of sales and cost and it worked. Thanks a lot for timely help.
Hi, @AdityaPowerBI
Please check the below picture and the sample pbix file's link down below.
It is for creating measures.
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
100 | |
76 | |
74 | |
49 |
User | Count |
---|---|
145 | |
108 | |
107 | |
89 | |
61 |