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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Mesure to count between 2 dates

Hello,

 

I am trying to create a measure that is able to count the number of distinct ticket numbers between two dates. I want to represent this in a matrix and a line graph, what I'm looking for is below. if I were to write it in a DAX measure formula it would look like this:

 

measure1 = calculate(distinctcount[ticket]),opendate >= x, close date <= x), however, I don't know what functions exist to filter the rows based on dates along an axis.

 

Data

TicketOpenClose
ticket 1may 1may 3
ticket 2may 2may 4
ticket 3may 3may 5
ticket 4may 4may 6
Ticket 5may 5may 7

 

Result

May 11
May 22
May 33
May 43
May 53
May 62
May 72
1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@Anonymous 

It will be something like this.  Your model will have to have a date table and that is where you would pull the date from.  It does not have to be joined to your ticket table.

Ticket Count:=
VAR MinDate = FIRSTDATE ( DATES[Date] ) 
VAR MaxDate = LASTDATE ( DATES[Date] ) 
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Data[Ticket] ),
            Data[Close Date] >= MinDate,
            Data[Open Date] <= MaxDate
    )

View solution in original post

3 REPLIES 3
jdbuchanan71
Super User
Super User

@Anonymous 

It will be something like this.  Your model will have to have a date table and that is where you would pull the date from.  It does not have to be joined to your ticket table.

Ticket Count:=
VAR MinDate = FIRSTDATE ( DATES[Date] ) 
VAR MaxDate = LASTDATE ( DATES[Date] ) 
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Data[Ticket] ),
            Data[Close Date] >= MinDate,
            Data[Open Date] <= MaxDate
    )
Anonymous
Not applicable

Hello,

 

That's excellent! I will have to test this and verify that it gives me the output that I'm looking for. As I'm testing this, is there any reason the following wouldn't work?

 

I can foresee an issue with the USERELATIONSHIP() function as this may confuse the dates, but as per the filter of  NOT(Data[Ticket Task Name] = "Receive Unit"), would this cause an issue? I think that it is possible that it may not give the intended result because of the data structure, but would it cause an error?

 

Ticket Count:=
VAR MinDate = FIRSTDATE ( DATES[Date] ) 
VAR MaxDate = LASTDATE ( DATES[Date] ) 
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Data[Ticket] ),
            Data[Close Date] >= MinDate,
            Data[Open Date] <= MaxDate,
            USERELATIONSHIP(DATES[Date],Data[Open Date]),
            NOT(Data[Ticket Task Name] = "Receive Unit"),
    )

 

I don't think it would cause an error but the dates would certainly cause your results to be different.  Instead of counting items where the open date <= the date it would only count items where the open date = the date

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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