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
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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.