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
pkoel-asb
Helper V
Helper V

Dax date variables

Hello All,

 

   I am trying to create a measure that will tell me the difference between two dates for a Credit that a user has filtered on. Here is my code:

DaysbetweenAssgined&Claimed = 
  var Startdate = if(CONTAINSSTRING('SpecConnect History'[Event],"Credit Awarded"),'SpecConnect History'[TimeStamp])
  Var Enddate = if(CONTAINSSTRING('SpecConnect History'[Event],"Customer Survey Submitted"),'SpecConnect History'[TimeStamp])
  return
      DATEDIFF((Startdate,Enddate,days)

 

I do not think I am doing my If's correctly. Any suggestions?

 

Cheers!

Peter

3 REPLIES 3
amitchandak
Super User
Super User

@pkoel-asb , in this case quite a few dates would be blank ,

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Hello,

 

   Thank you for the reply. Here is an image:

 

New Bitmap Image.png

Hello,

 

I have been able to create a test measure below:

Days From Assign to Customer Survey =
VAR StartDate =
SUMMARIZECOLUMNS (
'SpecConnect History'[TimeStamp],
KEEPFILTERS (
TREATAS ( { "Credit Awarded (via assignment)" }, 'SpecConnect History'[Event] )
),
KEEPFILTERS ( TREATAS ( { 27 }, 'SpecConnect History'[CreditID] ) )
)
VAR EndDate =
SUMMARIZECOLUMNS(
'SpecConnect History'[TimeStamp],
            KEEPFILTERS(
            TREATAS( {"Customer Survey Submitted"}, 'SpecConnect History'[Event] )
        ),
        KEEPFILTERS( TREATAS( {27}, 'SpecConnect History'[CreditID] ))
)
Var mDays=DATEDIFF(StartDate,EndDate,day)
return mDays
 
In the example, I used the query generator in DaxStudio. I had to hard code in a value for the Credit Id (27) in the example above. I want to get the value a user selected from a Slicer visual. How do I get that value into the Dax calculation?
 
Cheers!
 
Peter

 

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.