Forum Discussion

dorsey's avatar
dorsey
Regular Visitor
5 years ago
Solved

trouble with calculated column

Hello,

 

First sorry for my english.

I'm a very newby on powerBI but everything becom with a start no ?

I've a table with some column :

- [first] date for when the holiday start ,

- [second] date for when the holiday finish

- [third] who calculate the the day between this two date  expect unwork day and weekend, with DAX function (working at this point)

- [forth]one with 3 value (day, amp, pm)

everything is fine but I want to create an other colunn [Five] who say " if [forth} ="day", [Five] = [Third] else [Five] = 0,5 "

 

For that I've try this : 

Colonne = IF([forth]="day",[third],"0,5")
 
but I've an error like :  Expressions that return a variant data type cannot be used to define calculated columns.

 Do you have an idea to help me ?

 

Thank you very mush

  • Hey dorsey ,

     

    that usually happens when you mix data types.

    I guess [third] is number, no? Then try it like this:

    Colonne = IF( [forth]="day", [third], 0.5)

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
     
    Best regards
    Denis
     

4 Replies

  • dorsey's avatar
    dorsey
    Regular Visitor

    Hello,

     

     and thank you for your two help. It's working and it's awsome !!

     

    Nothing for you maybe but for me it's a big start !

     

    regards

    • selimovd's avatar
      selimovd
      Icon for Most Valuable Professional rankMost Valuable Professional

      Hey dorsey ,

       

      I'm happy it works now 😊

      The beginning is always the hardest. Keep going and things will become more and more easy. And we can always help you here in the community.

       

      Best regards

      Denis

  • HotChilli's avatar
    HotChilli
    Icon for Community Champion rankCommunity Champion

    the 2 return paths of an IF statement have to return the same datatype.  It looks like the code returns an integer or a string so that's what you need to fix.

  • selimovd's avatar
    selimovd
    Icon for Most Valuable Professional rankMost Valuable Professional

    Hey dorsey ,

     

    that usually happens when you mix data types.

    I guess [third] is number, no? Then try it like this:

    Colonne = IF( [forth]="day", [third], 0.5)

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
     
    Best regards
    Denis