Forum Discussion
Count Distinct Dates between 2 dates, by ID
- 8 years ago
Hi Anonymous,
The date column in Table1 and enddate column in Table2 are set to "Text" in your .pbix file. Please change their data type to "Date".
Best regards,
Yuliana Gu
Hi Anonymous,
Based on my understanding, the "StartDate" and "EndDate" are known values in a second table (suppose it's 'Table_2'), right?
That case, please create a calculated table to get your desired output.
Table_3 =
VAR temp =
FILTER (
CROSSJOIN (
Table_1,
SELECTCOLUMNS (
Table_2,
"ID2", Table_2[ID],
"StartDate", Table_2[Start Date],
"EndDate", Table_2[End Date]
)
),
[ID] = [ID2]
&& [Date] >= [StartDate]
&& [Date] <= [EndDate]
)
RETURN
SUMMARIZE (
temp,
[ID],
"StartDate", FIRSTNONBLANK ( Table_2[Start Date], 1 ),
"EndDate", FIRSTNONBLANK ( Table_2[End Date], 1 ),
"Distinct Count of Dates(value > 0)", CALCULATE ( DISTINCTCOUNT ( Table_1[Date] ), Table_1[Value] > 0 ),
"Sum of Value", SUM ( Table_1[Value] )
)
Best regards,
Yuliana Gu
- Anonymous8 years agoNot applicable
Tried but I got this error message
"DAX comparison operations do not support comparing values of type Text with values of type Date. Consider using the VALUE or FORMAT function to convert one of the values."
here's the pbix file
- v-yulgu-msft8 years ago
Microsoft Employee
Hi Anonymous,
The date column in Table1 and enddate column in Table2 are set to "Text" in your .pbix file. Please change their data type to "Date".
Best regards,
Yuliana Gu
- Anonymous8 years agoNot applicable
Spot on, thanks a bunch mate!