Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sagar512
Helper I
Helper I

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?

 

sagar512_1-1640078232848.png

 

Task Table   
Task NumberCategoryCreatedCreated +90
Task 1A1-Jan-211-Apr-21
Task 2A1-May-2130-Jul-21
Task 3B1-Sep-2130-Nov-21
Task 4B1-Jun-2130-Aug-21
Task 5B1-Dec-211-Mar-22

 

Ticket Table
Ticket NumberCreated
Ticket 17-Jan-21
Ticket 22-Feb-21
Ticket 32-Feb-21
Ticket 46-Jun-21
Ticket 510-Jun-21
Ticket 619-Aug-21
Ticket 79-Sep-21
Ticket 813-Jun-21
Ticket 93-Mar-21
Ticket 109-Sep-21
1 ACCEPTED SOLUTION

  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.
 smpa01_1-1640095276568.png
 
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
smpa01_0-1640096515863.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

15 REPLIES 15
smpa01
Super User
Super User

@sagar512  try this measure

Measure =
CALCULATE (
    COUNT ( 'Table 2'[Ticket Number] ),
    DATESBETWEEN (
        'Table 2'[Created],
        MAX ( 'Table 1'[Created] ),
        MAX ( 'Table 1'[Created +90] )
    )
)

 

smpa01_0-1640090786763.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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?

@sagar512  what do you mean?

 

smpa01_0-1640092717423.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I get below; If I remove the lowest level and add category

sagar512_0-1640094378910.png

 

  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.
 smpa01_1-1640095276568.png
 
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
smpa01_0-1640096515863.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I think this is what the exact challenge is; to make this measure work without including task number or date (lowest level) into the viz.

 

I am using powerbi dataset, so I can't even make this work using the calculated column.

@sagar512  for some reason, my previous reply got edited and I have edited back my original reply. Please take a look above.

It is not an issue, it is doable. Check the new measure.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@sagar512  when you are asking a question can you pleae make sure to include all the components? Do you wan to revise the previously provided sample data and include this new component?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Added the new column to the data (original post). 

smpa01
Super User
Super User

@sagar512  can you provide some sample data

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

For some reason I don't see a way to attach powerbi file; so added my tables to the original post.

will this help?

ValtteriN
Super User
Super User

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:
ValtteriN_0-1640080986927.png

 

End result:
ValtteriN_1-1640081009091.png

I hope this helps and if it does consider accepting this as a solution and giving a thumbs up!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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?

Hi,

It works almost exactly the same with a measure: 

tickets_ =
var _sdate = max('Task Table'[Created])
var _edate = max('Task Table'[C90]) return


calculate(COUNT(Tickets[TN]),DATESBETWEEN('Calendar'[Date],_sdate,_edate))
ValtteriN_0-1640089156013.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




thanks, but the problem with the above solution is I need to always keep the lowest level (Task number) into the context.


my end goal is to build some chart that aggregates to month level etc, but calculation should always stay at task number level and then aggregate.

I think the column was the best fit in this scenario but unfortunately, I can't use it due to direct query 😞

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors