Forum Discussion
Calculate Days between two dates - only for the current month
- 8 years ago
Hi DennisJung,
Based on my test, you should be able to follow steps below to get the expected result in your scenario.
1. Add a YearMonth column in your Date table if you don't have it yet.
YearMonth = YEAR('Date'[Date])*100+MONTH('Date'[Date])2. Use the formula below to create a new measure.
Measure = VAR firstDayOfMonth = MIN ( 'Date'[Date] ) VAR lastDayOfMonth = MAX ( 'Date'[Date] ) RETURN SUMX ( Table1, VAR s = MAX ( Table1[Start], firstDayOfMonth ) VAR e = MIN ( Table1[End], lastDayOfMonth ) RETURN IF ( s < e, DATEDIFF ( s-1, e, DAY ) ) )3. Show Name column as Rows, YearMonth column as Columns, and the measure as Values on the Matrix visual.
Here is the sample pbix file for your reference. :smileyhappy:
Regards
Hi DennisJung,
Based on my test, you should be able to follow steps below to get the expected result in your scenario.
1. Add a YearMonth column in your Date table if you don't have it yet.
YearMonth = YEAR('Date'[Date])*100+MONTH('Date'[Date])
2. Use the formula below to create a new measure.
Measure =
VAR firstDayOfMonth =
MIN ( 'Date'[Date] )
VAR lastDayOfMonth =
MAX ( 'Date'[Date] )
RETURN
SUMX (
Table1,
VAR s =
MAX ( Table1[Start], firstDayOfMonth )
VAR e =
MIN ( Table1[End], lastDayOfMonth )
RETURN
IF ( s < e, DATEDIFF ( s-1, e, DAY ) )
)
3. Show Name column as Rows, YearMonth column as Columns, and the measure as Values on the Matrix visual.
Here is the sample pbix file for your reference. :smileyhappy:
Regards
- DennisJung8 years ago
Helper I
Wow, thank you very much!
I found a solution yesterday by myself, but yours is 10 x better :D
My workaround was to create 3 calculated column for each month and 1 measure per month :/
Thank you!
- datanoob7 years agoNew Member
Hi, how would your solution for individual days?
- datanoob7 years agoNew Member
Hi, would your solution work for calculations for days? YearDay?