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.
How can I count the days between two dates which are defined as whole number i tabular and not as date in a dax measure?
For example:
firts date 20201201
last date 20210201
firstdate-lastdate= 63 days
I can't change the data type in tabular , there are other measures using this column.
Solved! Go to Solution.
Hello @Anonymous ,
you can transform the integer into a date and then calculate the difference with the DATEDIFF function:
Date Diff =
VAR vFistDate = DATE( LEFT( myTable[first date], 4 ), MID( myTable[first date], 5, 2 ), RIGHT( myTable[first date], 2 ) )
VAR vLastDate = DATE( LEFT( myTable[last date], 4 ), MID( myTable[last date], 5, 2 ), RIGHT( myTable[last date], 2 ) )
VAR vDiff = DATEDIFF( vFistDate, vLastDate, DAY )
RETURN
vDiff
Hello @Anonymous ,
you can transform the integer into a date and then calculate the difference with the DATEDIFF function:
Date Diff =
VAR vFistDate = DATE( LEFT( myTable[first date], 4 ), MID( myTable[first date], 5, 2 ), RIGHT( myTable[first date], 2 ) )
VAR vLastDate = DATE( LEFT( myTable[last date], 4 ), MID( myTable[last date], 5, 2 ), RIGHT( myTable[last date], 2 ) )
VAR vDiff = DATEDIFF( vFistDate, vLastDate, DAY )
RETURN
vDiff
Thank you @selimovd , I tested the measure and it works but not when the first and last day is the same day.
for example :
2019-05-14 2019-05-14 vDiff=0 (but it should be counted as 1 day, vDiff=1)
Hey @Anonymous ,
mathematically there is not a single day difference between today and today.
But if you want to count that as one day, then you should add +1 for all values to be consistent.
Then try:
Date Diff =
VAR vFistDate = DATE( LEFT( myTable[first date], 4 ), MID( myTable[first date], 5, 2 ), RIGHT( myTable[first date], 2 ) )
VAR vLastDate = DATE( LEFT( myTable[last date], 4 ), MID( myTable[last date], 5, 2 ), RIGHT( myTable[last date], 2 ) )
VAR vDiff = DATEDIFF( vFistDate, vLastDate, DAY )
RETURN
vDiff + 1
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
103 | |
101 | |
76 | |
66 | |
60 |
User | Count |
---|---|
142 | |
106 | |
103 | |
85 | |
70 |