Forum Discussion
Day Count between two dates - DAX Help
- Anonymous8 years ago
Hi Anonymous,
If you can't ensure which date column with be the small one, you should add some operation to get the specificity one.
As I write above, min and max function can used to auto return the matched date.
I build a sample table with random date store in date1 and date2, then I can use above formula to get the diff between these date column.
Table formula:
Sample = ADDCOLUMNS(GENERATESERIES(1,100,1),"Date1",RANDBETWEEN(DATE(2015,1,1),TODAY()),"Date2",RANDBETWEEN(DATE(2015,1,1),TODAY()))
Calculate column:
Diff = DATEDIFF(MIN([Date1],[Date2]),MAX([Date1],[Date2]),DAY)
Reuslt:
Regards,
Xiaoxin Sheng
Hi Anonymous,
Based on your description, I think DATEDIFF function will suitable for your requirement.
Sample: calculate column.
Day Count = DATEDIFF(MIN([Date 1],[Date 2]),MAX([Date 1],[Date 2]),DAY)
Regards,
Xiaoxin Sheng
Anonymous
This seems like it's a usable solution - however I noticed that in some cases I have a start date greater than an end date in some of the rows. Is there away to accommodate this in the DAX statement so that it will identify these rows and simply "error" but show results where it will work - like in the paste from excel below?
Thanks!