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
Anonymous
Not applicable

calculating DATEDIFF dynamically

Hi,

I need to calculate date range dynamically, so I have created a text box like below based on creation date:

Text Box.PNGand now I can get that value using the below DAX:

To Date = SELECTEDVALUE(Data[Creation Date], Data[Max First Touch Date])

Now I have a drop down value of number of date difference like below:

Day No.PNGand have got the value in a measure using the dax:

Day No Selected = format(SELECTEDVALUE('Day No'[Day No],1), "#")

 

So my requirement is to calculate the 'From Date' when like below:

Selected Creation Date + Selected Day No.

so how can I achieve it? please help

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,
I have modified the Dax as below:
From Date =
var Max_Date = format(MAXA(Data[FIRST_TOUCH_DATE_TIME]), "MM-DD-YYYY")
var To_Date = SELECTEDVALUE(Data[Creation Date], Max_Date)
var DayNo = format(SELECTEDVALUE('Day No'[Day No],1), "#")
Var From_Date = format(To_Date -DayNo, "MM-DD-YYYY")
return From_Date

and it works for me.

View solution in original post

3 REPLIES 3
d_gosbell
Super User
Super User

So my requirement is to calculate the 'From Date' when like below:

Selected Creation Date + Selected Day No.

so how can I achieve it? please help

 


Dates are stored internally as the number days since 31 Dec 1899 , so to add a given number of days to a date you can pretty much just write it exactly how you have it in your requirement

 

From Date = [Selected Creation Date] + [Selected Day No]

Anonymous
Not applicable

Hi,

I have created a measure like this:

Measure =
var Max_Date = format(MAXA(Data[FIRST_TOUCH_DATE_TIME]), "MM-DD-YYYY")
var To_Date = SELECTEDVALUE(Data[Creation Date], Max_Date)
var DayNo = format(SELECTEDVALUE('Day No'[Day No],1), "#")
Var From_Date = To_Date -DayNo
return From_Date
 
as per your suggestion, but it returns a number to me. Please help me how to resolve this.

 

Anonymous
Not applicable

Hi,
I have modified the Dax as below:
From Date =
var Max_Date = format(MAXA(Data[FIRST_TOUCH_DATE_TIME]), "MM-DD-YYYY")
var To_Date = SELECTEDVALUE(Data[Creation Date], Max_Date)
var DayNo = format(SELECTEDVALUE('Day No'[Day No],1), "#")
Var From_Date = format(To_Date -DayNo, "MM-DD-YYYY")
return From_Date

and it works for me.

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.