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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
vaalyushin
Helper I
Helper I

Distinct Count by filter

Good afternoon!

I need to get the number of open and closed applications. At the same time, the application may have a history of its states (open, in operation, closed, resolved)

My dataset:

ticket_numbercurrent_statuscreated_datestatus_date_change
1open1.01.20221.01.2022
1in progress2.01.20222.01.2022
2open2.02.20222.02.2022
2in progress2.02.20222.02.2022
2closed2.02.20222.02.2022
3open3.02.20233.02.2023
1 ACCEPTED SOLUTION

Hi @vaalyushin 
Here is the sample file with the solution https://www.dropbox.com/t/fZytnjZorSijq226
A new calculated column has to be created:

Status = 
VAR CurrentTicket = Tickets[ticket_number]
VAR CurrentTicketAllAvailableStatuses =
    FILTER (
        Tickets,
        Tickets[ticket_number] = CurrentTicket
    )
VAR Result =
    SWITCH (
        TRUE,
        CONTAINS ( CurrentTicketAllAvailableStatuses, Tickets[current_status], "Resolved" ), "Resolved",
        CONTAINS ( CurrentTicketAllAvailableStatuses, Tickets[current_status], "Closed" ), "Closed",
        CONTAINS ( CurrentTicketAllAvailableStatuses, Tickets[current_status], "Resolved" ), "Resolved",
        CONTAINS ( CurrentTicketAllAvailableStatuses, Tickets[current_status], "In Progress" ), "In Progress",
        "Open"
    )
RETURN
    Result 

The measure is a simple distinct count 

Ticket Count = 
    COUNTROWS ( DISTINCT ( Tickets[ticket_number] ) )

 You can use the newly caculated column in rows or slicers. And the measure will give you the distinct count as per your selection.

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

Hi @vaalyushin 
You have only options for the satus which are: Open, then it will become In Progress (In Operation) then it will be either Closed or Resolved. Am I right? Do you have other options?

Yes, you are right

Hi @vaalyushin 
Here is the sample file with the solution https://www.dropbox.com/t/fZytnjZorSijq226
A new calculated column has to be created:

Status = 
VAR CurrentTicket = Tickets[ticket_number]
VAR CurrentTicketAllAvailableStatuses =
    FILTER (
        Tickets,
        Tickets[ticket_number] = CurrentTicket
    )
VAR Result =
    SWITCH (
        TRUE,
        CONTAINS ( CurrentTicketAllAvailableStatuses, Tickets[current_status], "Resolved" ), "Resolved",
        CONTAINS ( CurrentTicketAllAvailableStatuses, Tickets[current_status], "Closed" ), "Closed",
        CONTAINS ( CurrentTicketAllAvailableStatuses, Tickets[current_status], "Resolved" ), "Resolved",
        CONTAINS ( CurrentTicketAllAvailableStatuses, Tickets[current_status], "In Progress" ), "In Progress",
        "Open"
    )
RETURN
    Result 

The measure is a simple distinct count 

Ticket Count = 
    COUNTROWS ( DISTINCT ( Tickets[ticket_number] ) )

 You can use the newly caculated column in rows or slicers. And the measure will give you the distinct count as per your selection.

Russell-PBI
Resolver II
Resolver II

Could you create a flag in your dataset to identify the latest status for each ticket based on created_date and a sort of the current_status, then filter for this in your report or within a measure?

ticket_numbercurrent_statuscreated_datestatus_date_changelatest_status_flag
1open1.01.20221.01.20220
1in progress2.01.20222.01.20221
2open2.02.20222.02.20220
2in progress2.02.20222.02.20220
2closed2.02.20222.02.20221
3open3.02.20233.02.20231

 

CALCULATE(COUNTROWS(YourDataset), latest_status_flag = 1)

Might be easier than trying to serve it all up in a measure.

 

EDIT: COUNTROWS.

I didn't fully understand what you meant. now I do it through the measure, but naturally I get the wrong result

 

CountOpenTickets = 
CALCULATE (
    DISTINCTCOUNT('tickets'[issue_number] ),
    FILTER (
        'tickets',
        'tickets'[current_status] = "Open"
            && 'tickets'[creation_date] = MAX ('jira_vulnerability_issues'[creation_date])
    )
)

 

This probably isn't the most streamlined solution as I don't use PowerQuery for transformations, but here is what I came up with: https://drive.google.com/file/d/16XYzwjHyqbhbhbSodc03yXOPorGpj_V3/view?usp=sharing

 

Effectively, it works out the latest created_date per ticket, the latest current_status based on what will most likely come after each status, then uses the combination of those two bits of information to decide which record is the latest per ticket. If that doesn't work because status will change back and forth, then you might need to consider adding date and time into your dataset rather than just date.

 

Thank you, It's nice, but i think it can be resolve with measure

@tamerj1's posted solution works with a calculated column and measure, so no messing about with PowerQuery. I'd say that's a good solution for you.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors