Forum Discussion
Why doesn't a column calculation work properly using a "What If " Parameter
- 8 years ago
Hi, calculated columns are only calculated when the data model is initialized (at load or refresh) which is BEFORE you interact with the model in any way (slicers, crossfiltering etc). So calculated columns will ALWAYS use default values for any slicers or disconnected tables.
Its the way PowerBI works. What is the reason your trying to add a calulated column vs displaying the measure in a visual?
Also I woudl AVOID using SUMX if at all possible. Its very innefecient, slow and resource intensive. Try
Discount Price MEASURE = SUM(Table1[Price]) * (1-MAX(Discount[Discount Value]))
Let PowerBI do the filter context for you. Finally assuming your discount table is a disconnected table that is NOT connected to your data I would reccommend a harvest measure to get the selected value and set a default if none (or more than one) discount is selected. In your case
Selected Discount = SELECTEDVALUE(Discount[Discount Value],0) // will default to 0 or no discount repalce with .1 or whatver you want as your default)
with this harvest masure your Discount Price Measure woudl be
Discount Price MEASURE = SUM(Table1[Price]) * [Selected Discount]
Hi, calculated columns are only calculated when the data model is initialized (at load or refresh) which is BEFORE you interact with the model in any way (slicers, crossfiltering etc). So calculated columns will ALWAYS use default values for any slicers or disconnected tables.
Its the way PowerBI works. What is the reason your trying to add a calulated column vs displaying the measure in a visual?
Also I woudl AVOID using SUMX if at all possible. Its very innefecient, slow and resource intensive. Try
Discount Price MEASURE = SUM(Table1[Price]) * (1-MAX(Discount[Discount Value]))
Let PowerBI do the filter context for you. Finally assuming your discount table is a disconnected table that is NOT connected to your data I would reccommend a harvest measure to get the selected value and set a default if none (or more than one) discount is selected. In your case
Selected Discount = SELECTEDVALUE(Discount[Discount Value],0) // will default to 0 or no discount repalce with .1 or whatver you want as your default)
with this harvest masure your Discount Price Measure woudl be
Discount Price MEASURE = SUM(Table1[Price]) * [Selected Discount]
Your statement that column values are determined ... BEFORE you interact with the model in any way ... has resolved my issue. The Power BI example I used was a very simple one but I now feel confident of repeating the same concepts on a much more complicated pbix that I am working on.
Thanks so much :smileyhappy: