Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Akkoustic
Frequent Visitor

Error: Expressions that yield variant data-type cannot be used to define calculated columns.

How do I solve this issue? I would like to create this Calculated column. 

 

CompletionStatus =
SWITCH(
TRUE();
TasksOpportunities[Status] = "Open" && TasksOpportunities[Days until Completion]<0;"Open";
TasksOpportunities[Status] = "Open" && TasksOpportunities[Days until Completion]>=0 && TasksOpportunities[Days until Completion]<7;"Open";
TasksOpportunities[Status] = "Open" && TasksOpportunities[Days until Completion]>7;"Standby";
TasksOpportunities[Status] = "Completed"; 0;
TasksOpportunities[Status] = "Cancelled"; 3;
BLANK()
)

 

[Status] = Text

[Days until Completion] = Whole number

1 ACCEPTED SOLUTION

Hi @Akkoustic 

Do you use the formula in a measure as below instead of a column?

7.png

If so, please modify the formula as below to use in a measure

CompletionStatus =
SWITCH (
TRUE (),
MAX ( TasksOpportunities[Status] ) = "Open"
&& MAX ( TasksOpportunities[Days until Completion] ) < 0, "Open",
MAX ( TasksOpportunities[Status] ) = "Open"
&& MAX ( TasksOpportunities[Days until Completion] ) >= 0
&& MAX ( TasksOpportunities[Days until Completion] ) < 7, "Open",
MAX ( TasksOpportunities[Status] ) = "Open"
&& MAX ( TasksOpportunities[Days until Completion] ) > 7, "Standby",
MAX ( TasksOpportunities[Status] ) = "Completed", "0",
MAX ( TasksOpportunities[Status] ) = "Cancelled", "3",
BLANK ()
)

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @Akkoustic 

Each result of the switch branch should be of same data type.

Try this instead

CompletionStatus =
SWITCH(
TRUE();
TasksOpportunities[Status] = "Open" && TasksOpportunities[Days until Completion]<0;"Open";
TasksOpportunities[Status] = "Open" && TasksOpportunities[Days until Completion]>=0 && TasksOpportunities[Days until Completion]<7;"Open";
TasksOpportunities[Status] = "Open" && TasksOpportunities[Days until Completion]>7;"Standby";
TasksOpportunities[Status] = "Completed"; "0";
TasksOpportunities[Status] = "Cancelled"; "3";
BLANK()
)

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Maggie,

Thanks for the explanation, this totally makes sense. 

Nevertheless I did get another error message when I tried your expression: 
A single value for column 'Status' in table 'TasksOpportunities' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

Do you know why this is and how to solve it? 

Hi @Akkoustic 

Do you use the formula in a measure as below instead of a column?

7.png

If so, please modify the formula as below to use in a measure

CompletionStatus =
SWITCH (
TRUE (),
MAX ( TasksOpportunities[Status] ) = "Open"
&& MAX ( TasksOpportunities[Days until Completion] ) < 0, "Open",
MAX ( TasksOpportunities[Status] ) = "Open"
&& MAX ( TasksOpportunities[Days until Completion] ) >= 0
&& MAX ( TasksOpportunities[Days until Completion] ) < 7, "Open",
MAX ( TasksOpportunities[Status] ) = "Open"
&& MAX ( TasksOpportunities[Days until Completion] ) > 7, "Standby",
MAX ( TasksOpportunities[Status] ) = "Completed", "0",
MAX ( TasksOpportunities[Status] ) = "Cancelled", "3",
BLANK ()
)

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.