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
Curious2115
Frequent Visitor

Tableau Calculated Field to Power BI Calculated Column

Hello,

 

I have this calculated field in Tableau that I am trying to convert into a calculated column in Power BI, but it is giving me a type error. I am going to use this calculated column to create other calculated column. What am I doing wrong? Any help would be greatly appreciated. Please see the codes below.

 

Tableau Code:

     IF DATEPART('month',[DATE]) = DATEPART('month',TODAY())
     and DATEPART('day',[DATE]) < DATEPART('day',TODAY())

     then int((DateDiff('month',[DATE],(DATEADD('month', 0, TODAY()))))/12)
     else int((DateDiff('month', [DATE],(DATEADD('month', -1, TODAY()))))/12) END

 

Power BI code:
       yr = IF('Document'[DATE].[Month] = MONTH(NOW())
       && 'Document'[DATE].[Day] < TODAY(),

       INT('Document'[DATE].[Month] - MONTH(NOW()))/12,
       INT('Document'.[Month] - (MONTH(NOw()) -1))/12)

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Curious2115 , Try like

 

yr = IF( month('Document'[DATE])= MONTH(today())
&& day('Document'[DATE]) < day(TODAY()),

datediff('Document'[DATE] , MONTH(today()), month)/12,
datediff('Document'[DATE] , MONTH(eomonth(today(),-1)), month)/12)

 

or

 

yr = IF( month('Document'[DATE])= MONTH(today())
&& day('Document'[DATE]) < day(TODAY()),

datediff('Document'[DATE] , MONTH(today()), month)/12,
datediff('Document'[DATE] , MONTH(date(year(today()),month(today())-1,day(today()))), month)/12)

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Curious2115 , Try like

 

yr = IF( month('Document'[DATE])= MONTH(today())
&& day('Document'[DATE]) < day(TODAY()),

datediff('Document'[DATE] , MONTH(today()), month)/12,
datediff('Document'[DATE] , MONTH(eomonth(today(),-1)), month)/12)

 

or

 

yr = IF( month('Document'[DATE])= MONTH(today())
&& day('Document'[DATE]) < day(TODAY()),

datediff('Document'[DATE] , MONTH(today()), month)/12,
datediff('Document'[DATE] , MONTH(date(year(today()),month(today())-1,day(today()))), month)/12)

Thank you!

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.

Top Solution Authors