Forum Discussion
adityavighne
Continued Contributor
6 years agoAdd target column to calculated table
Hi, I have calculated column and I want to add target for that and get difference value. How can I do this. Name,Open,Close and total is calculated table and Target, Difeerence column I want ...
Anonymous
6 years agoNot applicable
You have targets for each "Name" in a different table which you want to bring in this calculated table or you want to add the values by hard-coding them in the DAX and add it here?
- adityavighne6 years ago
Continued Contributor
Anonymous
I want to add target for each by hard coding.
- Anonymous6 years agoNot applicable
Hi,
You can use SWITCH statement to list target as 50 for A , 100 for B , 150 for C etc. SWITCH ("ColumnA","A",50,"B",100,"C",150,0)
Regards
Rohit
- AllisonKennedy6 years ago
Community Champion
adityavighne I think creating a table as Anonymous suggested and loading that into the Data Model would be a better solution, but you could use a Switch or IF to hard code this using ADDCOLUMNS or similar table constructor:
NewTable= ADDCOLUMNS(CalculatedTable, "Target", SWITCH(CalculatedTable[Name], "A", 50, "B", 60, "C", 100)
The difference can be added as a Calculated column or added into that table expression.
See this solution from v-lili6-msft for what we mean by having the target table stored in the data model and how to set that up with relationships (in your case replace 'year' with 'name')
https://community.powerbi.com/t5/Desktop/Adding-annual-target-to-existing-table/td-p/579550 - Anonymous6 years agoNot applicable
I think you should maintain your targets in a separate table, but if you want to hard-code it, you could do so as others suggested here using SWITCH. Refer to the screenshot below..