Forum Discussion

achen's avatar
achen
Frequent Visitor
7 years ago
Solved

Filtered Count from Another Table

Hi,

 

New user to PowerBi here and I am having a very hard time getting what I think should be a simple calculation.

 

I have 2 tables. 1 is "Orders" and another is "Incidents" that are linked by the "Order #".  I am trying to combine the two tables into a chart where it shows the number of "Pending" incidents per month (by "Incident Month") in a bar graph and the line graph will show the incident rate % (the number of "Pending" incidents dvided by the number of "Pending and "Service Request" Orders). Example of the desired graph shown below.

 

The bar graph is simple but I am having a lot of trouble getting the incident rate. I am having issues getting a count of the number of orders. All the things I have tired do not filter by month. I seem to just get a single number that doesnt break down into the months.

 

Can anyone explain what I am doing wrong?

 

ORDERS TABLE

Order #Order DateStatusType
O12-Oct-18PendingService Request
O215-Oct-18PendingReturn
O318-Oct-18CancelledService Request
O421-Oct-18PendingService Request
O527-Oct-18PendingService Request
O631-Oct-18PendingService Request
O71-Nov-18PendingService Request
O84-Nov-18PendingService Request
O95-Nov-18PendingService Request

 

INCIDENTS TABLE

Incident #Order #Incident DateStatus
I1O15-Oct-18Pending
I2O15-Oct-18Pending
I3O25-Oct-18Pending
I4O320-Oct-18Cancelled
I5O41-Nov-18Pending
I6O622-Nov-18

Pending

 

  • Anonymous's avatar
    Anonymous
    7 years ago

    The relationship will work.  Just many to many can lead to ambiguous models.  Anyhow, here's how I approached  this one:

     

    1. You are going to need a data table that will work as filter for Incidents and Orders:

    make sure to use fields from that table as your slicers, filters, ect.

     

    Then write a measure for Pending Incidents:

    Pending Incidents = CALCULATE(COUNTROWS(Incidents),Incidents[Status]="Pending")

    Then one for Pending and Service request from the Orders table:

    Pending and Service Request = CALCULATE(COUNTROWS(Orders),Filter(Orders,Orders[Status]="Pending" && Orders[Type] = "Service Request"))

    Then one last one to divide them out:

    Pending Incidents divided by Pending and Service = 
    DIVIDE([Pending Incidents], [Pending and Service Request])

    Here's the final table. I cannot for life of me find the combo chart though:

7 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    getting a number that seems to be a total and is repeating generally means there is a problem wiht the  relationships between the two tables.  Have a screenshot of the diagram view? 

     

    • achen's avatar
      achen
      Frequent Visitor

      I don't have access to the actual relationship dirgram, but I know that the only relationship between the two tables is the Order#

      • Anonymous's avatar
        Anonymous
        Not applicable

        That's a many to many relationship, which can have some interesting results.  Do you  have the option to create another table using Power Query?

  • achen's avatar
    achen
    Frequent Visitor

    Hi,

     

    Sorry if this is a repost but my original thread seems to have been removed.

     

    New user to PowerBi here and I am having a very hard time getting what I think should be a simple calculation.

     

    I have 2 tables. 1 is "Orders" and another is "Incidents" that are linked by the "Order #".  I am trying to combine the two tables into a chart where it shows the number of "Pending" incidents per month (by "Incident Month") in a bar graph and the line graph will show the incident rate % (the number of "Pending" incidents dvided by the number of "Pending and "Service Request" Orders). Example of the desired graph shown below.

     

    The bar graph is simple but I am having a lot of trouble getting the incident rate. I am having issues getting a count of the number of orders. All the things I have tired do not filter by month. I seem to just get a single number that doesnt break down into the months.

     

    Can anyone explain what I am doing wrong? What formula do I need in order to get the count of the order per month?

     

    ORDERS TABLE

    Order #Order DateStatusType
    O12-Oct-18PendingService Request
    O215-Oct-18PendingReturn
    O318-Oct-18CancelledService Request
    O421-Oct-18PendingService Request
    O527-Oct-18PendingService Request
    O631-Oct-18PendingService Request
    O71-Nov-18PendingService Request
    O84-Nov-18PendingService Request
    O95-Nov-18PendingService Request

     

    INCIDENTS TABLE

    Incident #Order #Incident DateStatus
    I1O15-Oct-18Pending
    I2O15-Oct-18Pending
    I3O25-Oct-18Pending
    I4O320-Oct-18Cancelled
    I5O41-Nov-18Pending
    I6O622-Nov-18

    Pending

     

    Desired Chart

    2018_12_12_14_09_29_Book6_Excel.png