Forum Discussion
Count Rows Falling between two dates ( from disconnected table )
Hi,
I am having two disconnected tables ( Task and Ticket).
On Task Table I need to count tickets (from the Ticket table) that fall between the task created date and Created +90 date.
In Excel, I used the below formula to get the expected output.
how can calculate the same in dax?
| Task Table | |||
| Task Number | Category | Created | Created +90 |
| Task 1 | A | 1-Jan-21 | 1-Apr-21 |
| Task 2 | A | 1-May-21 | 30-Jul-21 |
| Task 3 | B | 1-Sep-21 | 30-Nov-21 |
| Task 4 | B | 1-Jun-21 | 30-Aug-21 |
| Task 5 | B | 1-Dec-21 | 1-Mar-22 |
| Ticket Table | |
| Ticket Number | Created |
| Ticket 1 | 7-Jan-21 |
| Ticket 2 | 2-Feb-21 |
| Ticket 3 | 2-Feb-21 |
| Ticket 4 | 6-Jun-21 |
| Ticket 5 | 10-Jun-21 |
| Ticket 6 | 19-Aug-21 |
| Ticket 7 | 9-Sep-21 |
| Ticket 8 | 13-Jun-21 |
| Ticket 9 | 3-Mar-21 |
| Ticket 10 | 9-Sep-21 |
I still don't see an issue here
You need to display
'Table 1'[Created] and'Table 1'[Created +90] in the viz for the DAX to evaluate in the filter context. Without having that axis present, the expression will not evaluate.But if you do want to have that one displayed without bringing'Table 1'[Created] and'Table 1'[Created +90]then you need an index column and do this with a new measure
15 Replies
- ValtteriNCommunity Champion
Hi,
Here is one way to do this:Dax (calculated column):
Tickets = calculate(COUNT(Tickets[TN]),DATESBETWEEN('Calendar'[Date],'Task Table'[Created],'Task Table'[C90]))
Data model:
End result:I hope this helps and if it does consider accepting this as a solution and giving a thumbs up!
- sagar512Helper I
Thanks for the response; but unfortunately I cannot use the calculate function in the column, as I am working with powerbi data set (direct query).
Any way to do this in measure?
- ValtteriNCommunity Champion
Hi,
It works almost exactly the same with a measure:
tickets_ =var _sdate = max('Task Table'[Created])var _edate = max('Task Table'[C90]) returncalculate(COUNT(Tickets[TN]),DATESBETWEEN('Calendar'[Date],_sdate,_edate))
- sagar512Helper I
For some reason I don't see a way to attach powerbi file; so added my tables to the original post.
will this help?
- sagar512Helper I
I added a category column into my data and this measure needs the lowest level (task number) to work.
it's not working as expected if I remove the task number.
the calculation should always work on task level and then aggregate per report context
Any way we can achieve this?
- smpa01Community Champion