Forum Discussion

ericsara's avatar
ericsara
Helper I
4 years ago
Solved

Find a single value in a table based on multiple criteria

I have tables with columns as follows;

  • Tickets
    • Ticket Number
    • Ticket Name
    • Client ID
    • Status ID
    • Type ID
  • Client
    • Client ID
    • Name
    • Address
  • Status
    • Status ID
    • Name 
    • Description
  • Type
    • Type ID
    • Name
    • Description

 

What I am looking to return is the single ticket number that exists when

  1. Client is selected via a Slicer
  2. Status = Open
  3. Type = Management

 

It is possible that this could have more than one result.  In this case, I would want N/A as there should only be one result per client. 

What DAX would I need to find the one ticket for each client?

 

Below is some example data

 

Ticket Table

Ticket NumberTicket NameClient IDStatus IDType ID
AU-4589Management - Tables R US1000OPMAN
AU-4599Seup up account1000CLTAS
NZ-5100Management - Trucks n Trucks1001OPMAN
NZ-5645Help find keys1001OPSUP
NZ-6545Management - One Sock1002CLMAN

 

Client Table

Client IDNameAddress
1000Tables R US1 Your Place
1001Trucks n Trucks22 Me Drive
1002One Sock4 Lost Place

 

Status Table

Status IDNameDescription
OPOpenTicket is active
CLClosedTicket is closed

 

Type Table

Type IDNameDescription
MANManagementTo manage the overall status of your client
TASTaskAn item to out on your to do list
SUPSupportSupport raised by the client'

 

I am looking for a DAX expression that is something like this

 

Managament Ticket Number = 

Client is (Selected from a Slicer),

Status ID is OP

Type ID is MAN

 

So if the slicer listed all three clients and I then selected each one I want a Card visual to show the ticket number as follows

Client SelectedTicket Number shown in card
Tables R USAU-4589
Trucks n TrucksNZ-5100
One SockN/A (this is because the Management Ticket for this client is Closed)

 

I hope this helps add clarity to what I am looking to acheive. 

 

Thanks, 

 

 

  • Ended up using this DAX

     

    CALCULATE ( FIRSTNONBLANK('Tickets'[Ticket Number],1),'Status'[StatusID]="Open",'Type'[TypeID]="Client Management",'Client'[ClientID]=ClientID)
     
    Where ClientID is a lookup for the selected (using a slicer) client ID. 

7 Replies

  • mohammedadnant's avatar
    mohammedadnant
    Impactful Individual

    Hi ericsara 

     

    Pls try this DAX

    VAR _TicketCount = CALCULATE ( COUNTROWS(Tickets), Status[Name]="Open", Type[Name]="Management")
    RETURN
    IF ( _TicketCount > 1, "N/A", 1)

     

    If this is the answer to your query, please hit the like button. 

    Thanks & Regards,

    Mohammed Adnan

    Learn Power BI: https://www.youtube.com/c/taik18

    • ericsara's avatar
      ericsara
      Helper I

      Hi Mohammed,

      This does well to identify if there is only one ticket, but how do I return the Ticket Number?

      Cheers, 

      • mohammedadnant's avatar
        mohammedadnant
        Impactful Individual

        Hi ericsara 

         

        Try this

        VAR _TicketCount = CALCULATE ( COUNTROWS(Tickets), Status[Name]="Open", Type[Name]="Management")
        RETURN
        IF ( _TicketCount > 1, "N/A", MAX('Table'[Ticket Number]))

         

        or just this below as a new measure

        IF( HASONEVALUE('Table'[Ticket Number])=TRUE(), MAX('Table'[Ticket Number]), "N/A")

         

         

        If this is the answer to your query, please hit the like button. 

        Thanks & Regards,

        Mohammed Adnan

        Learn Power BI: https://www.youtube.com/c/taik18

  • Ended up using this DAX

     

    CALCULATE ( FIRSTNONBLANK('Tickets'[Ticket Number],1),'Status'[StatusID]="Open",'Type'[TypeID]="Client Management",'Client'[ClientID]=ClientID)
     
    Where ClientID is a lookup for the selected (using a slicer) client ID.