Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi guys,
I have a measure (amount) whose define my amount of raw material and a table with this columns
-raw material
-price
-amount
-date of purchase
What I need is another measure to define my price. For example, if my measure amount is 5000 for material 1 and my table is like:
raw material | price | amount | date of purchase |
material1 | 2,9 | 2000 | 18/dec/2023 |
material1 | 1,8 | 3500 | 20/dec/2023 |
material2 | 3,4 | 1000 | 12/dec/2023 |
material2 | 0,8 | 1500 | 10/oct/2023 |
I need to order my table by date of purchase descendent and calculate something like this:
3500*1,8 + (1500)*2,9 = 10650
Important, my amount is 5000, so I cant to surpass this amount, that's why I used 1500 instead of 2000 to multiply by 2,9.
How can I do this measure?
Solved! Go to Solution.
Hello @IgorAM,
Can you please try this:
Calculate Price =
VAR TotalAmountNeeded = 5000
VAR CumulativeTable =
ADDCOLUMNS(
FILTER(
'YourTable',
'YourTable'[raw material] = "material1"
),
"CumulativeAmount",
CALCULATE(
SUM('YourTable'[amount]),
FILTER(
ALL('YourTable'),
'YourTable'[date of purchase] <= EARLIER('YourTable'[date of purchase]) &&
'YourTable'[raw material] = EARLIER('YourTable'[raw material])
)
)
)
VAR Result =
SUMX(
CumulativeTable,
IF(
[CumulativeAmount] <= TotalAmountNeeded,
[amount] * [price],
MAX(0, TotalAmountNeeded - [CumulativeAmount] + [amount]) * [price]
)
)
RETURN
Result
Hello @IgorAM,
Can you please try this:
Calculate Price =
VAR TotalAmountNeeded = 5000
VAR CumulativeTable =
ADDCOLUMNS(
FILTER(
'YourTable',
'YourTable'[raw material] = "material1"
),
"CumulativeAmount",
CALCULATE(
SUM('YourTable'[amount]),
FILTER(
ALL('YourTable'),
'YourTable'[date of purchase] <= EARLIER('YourTable'[date of purchase]) &&
'YourTable'[raw material] = EARLIER('YourTable'[raw material])
)
)
)
VAR Result =
SUMX(
CumulativeTable,
IF(
[CumulativeAmount] <= TotalAmountNeeded,
[amount] * [price],
MAX(0, TotalAmountNeeded - [CumulativeAmount] + [amount]) * [price]
)
)
RETURN
Result
Thank you very much, @Sahir_Maharaj!
It is just what I needed, I just made some little changes, but the main logic is what you did!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
10 | |
10 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |