Forum Discussion

hummingbird's avatar
hummingbird
Helper II
2 years ago
Solved

Fault Percentage per Order

Hey,

 

I've got two tables that are interconnected by Order ID.

 

Table 1 contains all order information and Table 2 has 3 columns: Order ID, Fault Type and Fault Percentage. There can be multiple faults per order and the max sum of percentage adds up to 100.

 

Table 1

Order IDDateProductCustomer
13201/01/2023PistonJake
13302/01/2023Gear BoxLisa

 

Table 2

Order IDFault TypeFault Percentage
132Mechanical100
132Appearance0
133Mechanical0

 

I am looking for a solution that calculates the sum of the Fault Percentage (Mechanical + Appearance + other types) per each order. Then, if the fault percentage of an order is 0-40% then Green, 40-50% Amber and 50-100% Red.

 

Finally, I want to rank each product by Fault Percentage: my calculating the number of orders that are Red, Amber or Green vs total number of orders for that product. 

 

What is the best approach to achieve this using measures? Thank you!

  • Fowmy's avatar
    Fowmy
    2 years ago

    hummingbird 

    Add the order number from Table1 to a table visual and the following measure:

     

    Fault Measure = 
    VAR __SumFault = SUM('Table2'[Fault Percentage])
    VAR __Result = 
        SWITCH(
            TRUE(),
            __SumFault <=  0.4 ,  "Green",
            __SumFault >  0.4 && __SumFault <=  0.5 ,  "Amber",
            "Red"
        )
    RETURN
        __Result
             

     

3 Replies

  • hummingbird 

    Your Table1 has one product in your example per order, what if there are multiple products per order, then your relationship will break. if you have one-to-many.

    More details required for your second question.

    • hummingbird's avatar
      hummingbird
      Helper II

      Thanks. Let's assume there is only one product per order ID and we just need to know the sum of faults from the second table.

      • Fowmy's avatar
        Fowmy
        Super User

        hummingbird 

        Add the order number from Table1 to a table visual and the following measure:

         

        Fault Measure = 
        VAR __SumFault = SUM('Table2'[Fault Percentage])
        VAR __Result = 
            SWITCH(
                TRUE(),
                __SumFault <=  0.4 ,  "Green",
                __SumFault >  0.4 && __SumFault <=  0.5 ,  "Amber",
                "Red"
            )
        RETURN
            __Result