Forum Discussion
Need help with this fromula
- Anonymous2 years ago
Hi Anonymous ,
For your card vision object that has no value inside and the value of measure2 is not calculated correctly, we can try to solve this by splitting the measure into two parts for use.
Measure 2 = CALCULATE(MAX('combined_data 1'[Price]), FILTER('combined_data 1','combined_data 1'[Cut]=VALUES('combined_data 1'[Cut])&&'combined_data 1'[Month]=VALUES('combined_data 1'[Month]) ) )Measure 3 = SUMX('combined_data 1','Parameter'[Measure]*[Measure 2])For your second question, we can try using calculated columns and a new table to aggregate the data.
Column = SUMX(FILTER('Table','Table'[Date]=EARLIER('Table'[Date])),'Table'[Quantity])Table 2 = SUMMARIZE('Table','Table'[Date],"TotalQuantity",SUM('Table'[Quantity]))For your new request I have updated the pbix file, I hope it helps you, it's my pleasure to help you.
Hope it helps!
Best regards,
Community Support Team_ Tom ShenIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
For the problem you are experiencing, the use of temporary tables can solve your needs. Temporary tables can be used to dynamically adjust quantities and calculate new price values without changing the original data.
Below is an example of my data that I hope will help you.
1.declaration of percentage change variables, e.g., 5 per cent increase
DECLARE @percentage_change DECIMAL(5, 2) = 0.05;
2.Creation of temporary tables to adjust quantities
CREATE TABLE #adjusted_records (
id INT,
adjusted_quantity DECIMAL(10, 2),
category INT,
month INT
);
3.Insert the adjusted data into the temporary table
INSERT INTO #adjusted_records (id, adjusted_quantity, category, month)
SELECT
id,
quantity * (1 + @percentage_change),
category,
month
FROM
records;
4.Use the temporary table to calculate the new values and summarize
WITH computed_values AS (
SELECT
ar.id,
ar.adjusted_quantity,
pe.price,
(ar.adjusted_quantity * pe.price) AS new_value
FROM
#adjusted_records ar
JOIN
price_entry pe
ON
ar.month = pe.month AND ar.category = pe.category
)
SELECT
SUM(new_value) AS total_sum
FROM
computed_values;
-- Drop the temporary table
DROP TABLE #adjusted_records;
If you have any other questions, I've found the following document to help you out, and I hope it helps.
Temporal tables - SQL Server | Microsoft Learn
Hope it helps!
Best regards,
Community Support Team_ Tom Shen
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous2 years agoNot applicable
Hi,
Is there a way to do this in Power Bi? I see this solution is in SQL server.
- Anonymous2 years agoNot applicable
Here are some pictures of what I am working with
Basically looking to take quantity, multiply it by percent change and then take the new values and multiply them by the price values based on the "month" and "cut"
- Anonymous2 years agoNot applicable
Hi Anonymous ,
For your question, we tried to do it using two calculation columns to meet the requirement, the first calculation column to find the change in quantity and percentage, and then the second calculation column to find the new value and multiply them by the price value based on "month" and "cut", hope this helps you! I hope this helps, if there are any other questions, please contact me at the first time, I will continue to help you answer.
Adjusted Quantity = 'combined_data'[Quantity]*(1+'combined_data'[Percent Change]/100)New value = 'combined_data'[Adjusted Quantity]* CALCULATE( MAX('combined_data'[Price]), FILTER('combined_data', 'combined_data'[Cut]=EARLIER('combined_data'[Cut])&&'combined_data'[Month]=EARLIER('combined_data'[Month]) ) )Hope it helps!
Best regards,
Community Support Team_ Tom ShenIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous2 years agoNot applicable
Hi,
this is really good, but I have a few questions. You mention "we tried it using two calculation columns". Does that mean you created new measures or columns? Also, I would like the percent change to be something you can change with a slicer and the final value changes dynamcially as you change the slicer. Also, I do not want to put the percent changes in the SQL table.
Thanks!