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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
LIAMLI
New Member

Reporting constant errors:variant data-type cannot be used to define calculated columns

Hi,
I have a table named: FACT_Stock, I want to create a calculated column to define remaining shelf life (months).
Mine methodology is to use Column [EXP], [PictureDate], these two colum type is date, [EXP] is mixed with some blanks.
Formula of Remaining shelf life (months) is written as 

[RSL] =
VAR Months = IF(FACT_Stock[EXP] = BLANK(), BLANK(), DATEDIFF(FACT_Stock[PictureDate],FACT_Stock[EXP],MONTH))
RETURN
IF(
    Months = BLANK(),
    "Undefined",
    SWITCH(
        TRUE(),
        Months <= 0,
        "Expired",
        Months >= 48,
        "Not relevant",
        Months
    )
)

It keeps reporting errors: Expressions that yield variant data-type cannot be used to define calculated columns. I tried serveral ways to fix the error, such as use CONVERT formula to transform data type, but the error doesn't diappear

2 REPLIES 2
PhilipTreacy
Super User
Super User

Hi @LIAMLI 

 

Plese supply a representataive sample of your data (or all of it), so we can see what your working with.  Really hard to debug something without seeing the data.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi Philip,
Table is like this way

ItemCodeEXPSOHPictureDate
H0844900012021/11/14702024/3/31
H0845600012022/5/14602024/3/31
H0845600012022/3/14132024/3/31
H0845600012022/5/14402024/3/31
H0845600012999/12/31102024/3/31
H0845800012022/4/14602024/3/31
H0845800012022/6/14142024/3/31
H0845800012022/6/1462024/3/31
H0845800012023/4/18502024/3/31
H0845800012022/6/14152024/3/31
CBLM250 192024/3/31
CBLM250 362024/3/31
CBLM250T 12024/3/31
CBLM250T 72024/3/31
505512026/12/204392024/3/31
498312026/7/1838292024/3/31
498312026/7/1852024/3/31
505512026/6/21157222024/3/31
498312026/3/3112024/3/31
509412026/3/304962024/3/31
CL20811T 342024/3/31
CL20811T 7672024/3/31
CL20811TT 92024/3/31
H2820300012099/1/1122024/4/1
H2820500012099/1/1542024/4/1
H2850100012099/1/1152024/4/1
H3280100012099/1/198752024/4/1

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.