Forum Discussion
Anonymous
6 years agoNot applicable
Count dates between two dates excluding dynamic days
Hi community, I've this table, and I want to return the count of days between two dates and exclude all "False" days (monday, or tuesday, or wednesday...). Example: id DataInicio DataFim...
- 6 years ago
Hi Anonymous ,
Please refer to the following measure:
Measure = VAR days = DATEDIFF ( MAX ( 'Table'[DataInicio] ), MAX ( 'Table'[DataFim] ), DAY ) + 1 VAR selected_dates = ADDCOLUMNS ( GENERATESERIES ( MAX ( 'Table'[DataInicio] ), MAX ( 'Table'[DataFim] ) ), "Weekday", WEEKDAY ( [Value], 3 ) ) VAR mcount = IF ( MAX ( 'Table'[Monday] ) = "False", COUNTROWS ( FILTER ( selected_dates, [Weekday] = 0 ) ), 0 ) VAR tcount = IF ( MAX ( 'Table'[Tuesday] ) = "False", COUNTROWS ( FILTER ( selected_dates, [Weekday] = 1 ) ), 0 ) VAR wcount = IF ( MAX ( 'Table'[Wednesday] ) = "False", COUNTROWS ( FILTER ( selected_dates, [Weekday] = 2 ) ), 0 ) VAR Tucount = IF ( MAX ( 'Table'[thursday] ) = "False", COUNTROWS ( FILTER ( selected_dates, [Weekday] = 3 ) ), 0 ) VAR fcount = IF ( MAX ( 'Table'[friday] ) = "False", COUNTROWS ( FILTER ( selected_dates, [Weekday] = 4 ) ), 0 ) VAR sacount = IF ( MAX ( 'Table'[saturday] ) = "False", COUNTROWS ( FILTER ( selected_dates, [Weekday] = 5 ) ), 0 ) VAR suncount = IF ( MAX ( 'Table'[sunday] ) = "False", COUNTROWS ( FILTER ( selected_dates, [Weekday] = 6 ) ), 0 ) RETURN ( days - ( mcount + tcount + wcount + Tucount + fcount + sacount + suncount ) )If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai
v-deddai1-msft
6 years agoCommunity Support
Hi Anonymous ,
Please refer to the following measure:
Measure =
VAR days =
DATEDIFF ( MAX ( 'Table'[DataInicio] ), MAX ( 'Table'[DataFim] ), DAY ) + 1
VAR selected_dates =
ADDCOLUMNS (
GENERATESERIES ( MAX ( 'Table'[DataInicio] ), MAX ( 'Table'[DataFim] ) ),
"Weekday", WEEKDAY ( [Value], 3 )
)
VAR mcount =
IF (
MAX ( 'Table'[Monday] ) = "False",
COUNTROWS ( FILTER ( selected_dates, [Weekday] = 0 ) ),
0
)
VAR tcount =
IF (
MAX ( 'Table'[Tuesday] ) = "False",
COUNTROWS ( FILTER ( selected_dates, [Weekday] = 1 ) ),
0
)
VAR wcount =
IF (
MAX ( 'Table'[Wednesday] ) = "False",
COUNTROWS ( FILTER ( selected_dates, [Weekday] = 2 ) ),
0
)
VAR Tucount =
IF (
MAX ( 'Table'[thursday] ) = "False",
COUNTROWS ( FILTER ( selected_dates, [Weekday] = 3 ) ),
0
)
VAR fcount =
IF (
MAX ( 'Table'[friday] ) = "False",
COUNTROWS ( FILTER ( selected_dates, [Weekday] = 4 ) ),
0
)
VAR sacount =
IF (
MAX ( 'Table'[saturday] ) = "False",
COUNTROWS ( FILTER ( selected_dates, [Weekday] = 5 ) ),
0
)
VAR suncount =
IF (
MAX ( 'Table'[sunday] ) = "False",
COUNTROWS ( FILTER ( selected_dates, [Weekday] = 6 ) ),
0
)
RETURN
( days - ( mcount + tcount + wcount + Tucount + fcount + sacount + suncount ) )
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai
Anonymous
6 years agoNot applicable
- v-deddai1-msft6 years agoCommunity Support
Hi Anonymous ,
Would you please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai
- Anonymous6 years agoNot applicable
v-deddai1-msft , can you help me just in one last question?
If I have a calendar table, I get this error when I can't get any matches