Forum Discussion
What's wrong with my IF statement?
I have a report table with data grouped by Contract number. I tried creating a New Column that should contain the value of CurrEstCost if ProjCost equals zero, else it will contain the ProjCost number. Simple enough, but whenever there are entries in both CurrEstCost and ProjCost, the result is the sum of the two.
I thought that the logic for the new column would be based on the values of the rolled up Contract numbers, but it seems to be looking at the detail records that make up the contract totals.
I hope that I'm explaining this clearly. I appreciate any help.
What I can see from your formula is a new column. Columns are precompoded at the row level (that is, by line level).
You can test a measure, but remember to visual display row context.
Medida: if(sum(backlog[prjcost])-0,sum(backlog[currEstcost]),sum(backlog[prjcost]))
See also
https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/
7 Replies
- tkirilov
Resolver I
Hi Anonymous ,
I'm not sure what causes that kind of behaviour in your calculated column, but I would recommend that for a task like that you use the Add conditional column facility in the Query Editor.
Hope that helps,
Tom
- amitchandak
Super User
You are looking at this data in a visual, where the column might have already grouped if not on the line level.
Can you go to the data view and check this in the table. It seems two or more rows of data is added at the visual level.
- AnonymousNot applicable
It is the grouped numbers on the visual that I want the IF statement to act on.
In the data view, no line item has entries in both CurrEstCost and ProjCost, so the IF logic won't work there.
- amitchandak
Super User
What I can see from your formula is a new column. Columns are precompoded at the row level (that is, by line level).
You can test a measure, but remember to visual display row context.
Medida: if(sum(backlog[prjcost])-0,sum(backlog[currEstcost]),sum(backlog[prjcost]))
See also
https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/