Forum Discussion
New Column With Switch Statement Errors
Hi BrianNeedsHelp
In DAX, measures and calculated columns serve different purposes and contexts. Unfortunately, you cannot directly use a measure in a calculated column because measures are evaluated in the context of the entire dataset, while calculated columns are evaluated row by row within a table.
You need to ensure that the logic used in your measure is translated into a row-by-row context.
You can try this:
GACategory =
VAR GrossAddsValue = [Gross Adds] -- Replace this with the logic to calculate Gross Adds for each row
RETURN SWITCH(
TRUE(),
GrossAddsValue <= 45, "Low",
GrossAddsValue > 45 && GrossAddsValue <= 70, "Mid",
GrossAddsValue > 70, "High"
)
Hope this helps!!
If this solved your problem, please accept it as a solution and a kudos!!
Best Regards,
Shahariar Hafiz
- BrianNeedsHelp1 year agoResolver I
I think there was another visual causing errors. So I started over on another tab, and put this in like you mentioned:
GACategory = VAR GAs = sumx(VALUES('Location'[Location]),[Gross Adds]) REturn SWITCH( TRUE(), GAs<=45,"Low", GAs>=45 && GAs<=70,"Mid", GAs>70, "High" )Now I'm getting "this query uses more memory than the limit". So it may be that I need to query it down further? Not certain but the same thing works perfect in a measure.
- shafiz_p1 year agoSuper User
Your used functions are quite memory-intensive especially with large datasets. Anyway, if possible please share pbix. Without knowing what you are trying to achieve it is hard to give solution.
Solution provided earlier was not any concreate solution. Just want you to remember, that calculated column works row by row. It checks that the current row satisfy condition, if, then put it in calculation.
I don't know about your [Gross Adds] measure or it is a column or not. You are summing up gross adds for each location and then compare value to tagging each row (In which table). So, what is the relation between each row (where this column will be developed) and the gross adds, not very clear.
For example, I have a product table with price column where each row is a complete product info. I want to tag price with Low, Mid and High. I would then do simple:
Category =
SWITCH (
TRUE(),
Product[Price] <= 100, "Low",
Product[Price] > 100 && Product[Price] <= 500, "Mid",
"High"
)