Forum Discussion

gautampruthi's avatar
gautampruthi
Icon for Helper II rankHelper II
2 years ago
Solved

Mathematical operation from non joined table

Hi, 
I have two table Table 1 and Table 2.

Table 1 contain Course Group and status and and thier respective sum 

Course GroupConfirmedConditional FirmOffers to be acceptedPending ApplicationsInsurance
First Degree1424583235423
First Degree with Fnd Yr1081301719169
Other Undergraduate46236
Primary ITE711121372
Secondary ITE223125
Primary PGCE9736480
Secondary PGCE7735920
Postgraduate1517490


Table 2 contain Target grouped for Course Group 

GroupTarget
First Degree709
First Degree with Fnd Yr220
Other Undergraduate111
Postgraduate224
Primary ITE120
Primary PGCE158
Secondary ITE30
Secondary PGCE154


Now i want to get 0.9 *((Sum of Confirmed)+(Sum of conditional firm) - Target
this should give output as 

First Degree-164
First Degree with Fnd Yr-8
Other Undergraduate-6
Primary ITE-14
Secondary ITE-8
Primary PGCE-79
Secondary PGCE-77
Postgraduate-31


I am finding difficult to join the two table as i am getting many to many relationship and is there any way i can complete my requirements.


  • I'm not sure why you have M:M relationship, as i don't see any duplicates in your dataset. However, to fix it, you can consider creating a Table which contains all unique Group values, then using that to create 1:M relationships

     - this is the group table (I created this through Power Query)

     

     - and then I can get 1:M relationships since each value in the group table is unique.

     

    The other way to do it would be through DAX:
    In this example, i'm assuming that Table 1 has all the Course Groups listed:

    Output = 
    var summaryTable = ADDCOLUMNS(VALUES('Table'[Course Group]), 
        "confirmed and conditional", CALCULATE(SUM('Table'[Confirmed]) + SUM('Table'[Conditional Firm])) * 0.9,
        "target", CALCULATE(SUM('Table (2)'[Target]), TREATAS(VALUES('Table'[Course Group]), 'Table (2)'[Group]))
    )
    RETURN SUMX(summaryTable, [confirmed and conditional] - [target])

    note - i can't match your output exactly because i don't know where that missing bracket in your formula goes, but you can play around with the above. Hope that helps.

     

2 Replies

  • I'm not sure why you have M:M relationship, as i don't see any duplicates in your dataset. However, to fix it, you can consider creating a Table which contains all unique Group values, then using that to create 1:M relationships

     - this is the group table (I created this through Power Query)

     

     - and then I can get 1:M relationships since each value in the group table is unique.

     

    The other way to do it would be through DAX:
    In this example, i'm assuming that Table 1 has all the Course Groups listed:

    Output = 
    var summaryTable = ADDCOLUMNS(VALUES('Table'[Course Group]), 
        "confirmed and conditional", CALCULATE(SUM('Table'[Confirmed]) + SUM('Table'[Conditional Firm])) * 0.9,
        "target", CALCULATE(SUM('Table (2)'[Target]), TREATAS(VALUES('Table'[Course Group]), 'Table (2)'[Group]))
    )
    RETURN SUMX(summaryTable, [confirmed and conditional] - [target])

    note - i can't match your output exactly because i don't know where that missing bracket in your formula goes, but you can play around with the above. Hope that helps.

     

  • To achieve your requirements in Power BI, you can create a new table that combines and calculates the necessary values from Table 1 and Table 2. Here's a step-by-step guide to do this:

    1. Ensure Your Tables Have the Proper Relationships
      • Table 1 should have the Course Group and the different statuses.
      • Table 2 should have the Course Group and the Target.
    2. Create Relationships

    Ensure there's a relationship between Table 1 and Table 2 on the Course Group column. If you face a many-to-many relationship issue, consider creating a bridge table with unique Course Group values.

    1. Create a Calculated Table or Measure for the Calculation

    You can use DAX to create a new calculated table or measure that will perform the calculation. For simplicity, let's create a measure.

    Steps in Power BI

    1. Create a Relationship

    Ensure both tables are related on the Course Group column.

    1. Create a Measure

    Create a new measure to perform the calculation:

    Result =

    VAR Sum_Confirmed = SUM('Table 1'[Confirmed])

    VAR Sum_ConditionalFirm = SUM('Table 1'[Conditional Firm])

    VAR TargetValue = SUM('Table 2'[Target])

    RETURN

    0.9 * (Sum_Confirmed + Sum_ConditionalFirm) - TargetValue

    This measure calculates the desired value for each Course Group.

    1. Create a Table to Display Results

    Use the Result measure in a new table visual to display the results:

      • Add the Course Group column from Table 1 or Table 2 (since they are related, it doesn't matter).
      • Add the Result measure to the Values.

    Example DAX Measure

    Result =

    SUMX(

        VALUES('Table 1'[Course Group]),

        0.9 * (

            CALCULATE(SUM('Table 1'[Confirmed])) +

            CALCULATE(SUM('Table 1'[Conditional Firm]))

        ) -

        CALCULATE(SUM('Table 2'[Target]))

    )

    Expected Output

    Course Group

    Result

    First Degree

    -164

    First Degree with Fnd Yr

    -8

    Other Undergraduate

    -6

    Primary ITE

    -14

    Secondary ITE

    -8

    Primary PGCE

    -79

    Secondary PGCE

    -77

    Postgraduate

    -31

    This approach ensures you calculate the required values based on the relationships between Table 1 and Table 2. The use of the SUMX function iterates over each Course Group, performing the calculation and summing the results.