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
mdaamirkhan
Post Prodigy
Post Prodigy

revenue this year and revenue this year+1

Hi All

 

I need help on the folloing logic what will be dax

 

revenue this year = if("contract end date"- 01/01/this year)<12 then ("contract end date"- 01/01/this year) else 12


revenue this year+1 = if("contract end date"- 01/01/this year+1)<12 then ("contract end date"- 01/01/this year+1) else 12

1 ACCEPTED SOLUTION
DataZoe
Employee
Employee

@mdaamirkhan I am not 100% sure what the expected outcome you are looking for here is, but the logic you have outlined in a measure could look like this:

 

Revenue This Year =
VAR MaxEndDate = MAX ( Table[Contract End Date] )
VAR ThisYear = DATE ( YEAR ( TODAY () ), 1, 1 )
VAR Diff = MaxEndDate - ThisYear
RETURN
IF ( Diff < 12, Diff, 12 )

 

Revenue This Year +1 =
VAR MaxEndDate = MAX ( Table[Contract End Date] )
VAR ThisYear = DATE ( YEAR ( TODAY () ), 1, 1 )
VAR Diff = MaxEndDate - (ThisYear+1)
RETURN
IF ( Diff < 12, Diff, 12 )

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

Your question is not clear.  Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
DataZoe
Employee
Employee

@mdaamirkhan I am not 100% sure what the expected outcome you are looking for here is, but the logic you have outlined in a measure could look like this:

 

Revenue This Year =
VAR MaxEndDate = MAX ( Table[Contract End Date] )
VAR ThisYear = DATE ( YEAR ( TODAY () ), 1, 1 )
VAR Diff = MaxEndDate - ThisYear
RETURN
IF ( Diff < 12, Diff, 12 )

 

Revenue This Year +1 =
VAR MaxEndDate = MAX ( Table[Contract End Date] )
VAR ThisYear = DATE ( YEAR ( TODAY () ), 1, 1 )
VAR Diff = MaxEndDate - (ThisYear+1)
RETURN
IF ( Diff < 12, Diff, 12 )

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

Its not working in 2022 i have only Jan so it should return number of month 1

Revenue This Year +1 =
VAR MaxEndDate = MAX ( Table[Contract End Date] )
VAR ThisYear = DATE ( YEAR ( TODAY () ), 1, 1 )
VAR Diff = MaxEndDate - (ThisYear+1)
RETURN
IF ( Diff < 12, Diff, 12 )

Capture.JPG

@mdaamirkhan 

Try this:

Revenue This Year +1 =
VAR MaxEndDate = MAX ( Table[Contract End Date] )
VAR ThisYear = DATE ( YEAR ( TODAY () )+1, 1, 1 )
VAR Diff = (DATEDIFF(ThisYear,MaxEndDate,MONTH)) +1
RETURN
IF ( Diff < 12, Diff, 12 )

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

Hi @mdaamirkhan ,

 

Im not sure exactly what you want , but it could be like this :

 

Revenue This Year =

VAR MaxEndDate = MAX ( 'Contract End Date'[Contracts end data])

VAR ThisYear = DATE ( YEAR ( TODAY () ), 1, 1 )

VAR Diff = DATEDIFF(ThisYear,MaxEndDate,MONTH)

RETURN IF ( Diff < 12, Diff, 12 )

 

 

Revenue This Year +1 =

VAR MaxEndDate = MAX ('Contract End Date'[Contracts end data] )

VAR ThisYear = DATE ( YEAR ( TODAY () )+1, 1, 1 )

VAR Diff = (DATEDIFF(ThisYear,MaxEndDate,MONTH)) +1

RETURN IF ( Diff < 12, Diff, 12 )

 

 

Through two variables to get var diff ,and then output the result by judging the condition .

 

The effect is as shown(The specified time is 2021/01/01):

Ailsa-msft_0-1616400202616.png

 

Ailsa-msft_1-1616400202618.png

 

 

Ailsa-msft_2-1616400202619.png

 

 

 

Best Regards

Ailsa Tao

Not working coz it return 1 only 

As per your query  it return 12 which wrong it should show 5
Revenue This Year =
VAR MaxEndDate = MAX ( Table[Contract End Date] )
VAR ThisYear = DATE ( YEAR ( TODAY () ), 1, 1 )
VAR Diff = MaxEndDate - ThisYear
RETURN
IF ( Diff < 12, Diff, 12 )

 

Capture.JPG

@mdaamirkhan The logic you provided assumes the difference is in months, not days? If that is what you are looking for, then try this change:

 

Revenue This Year =
VAR MaxEndDate = MAX ( Table[Contract End Date] )
VAR ThisYear = DATE ( YEAR ( TODAY () ), 1, 1 )

VAR Diff = DATEDIFF(ThisYear,MaxEndDate,MONTH)

RETURN
IF ( Diff < 12, Diff, 12 )

 

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

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.