Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Adding a total matrix from a different data set

I have two HR data sets below; one is data of all employees by department and categories (total population) and the second is the data set of employees that left and their leave reason (departure data).

There is less data in the departure data set and the employee IDs are not always matching it wouldn't make sense to join.

My desired result is the last table below. The blue part is a summary of the departure data. I can do the blue part of the table in PowerBI but I cannot add the yellow and red part (summary of total employees and leave rate by department and categories). When I try it just put 16 in all rows. Is there a way to do this in PowerBI? I looked into this: https://exceleratorbi.com.au/building-a-matrix-with-asymmetrical-columns-and-rows-in-power-bi/   but its not the same problem. The total and the departures are not in the same data set in my case.

Note: These are hypothetical examples, and my data sets have more rows.

Thanks.

 

 

total population: 

departure data set:

Desired result:

  

 

 

data:

IDcategorieDepartment
1011BD1
1002BD1
1004CD2
1011CD2
1012AD2
1013AD1
1014CD2
1009BD2
1016BD2
1017CD2
1018AD3
1019CD2
1020BD2
1021BD3
1022BD3
1023AD1

 

IDcategorieDepartmentLeave reason
1001AD1Retirement
1002BD1Lay-off
1003CD3Retirement
1004CD2Resignation
1005AD2Resignation
1006AD1Retirement
1007CD2Lay-off
1008BD3Retirement
1009BD2Resignation
1010CD1Discharge
  • Hi Anonymous ,

    According to your description, Matrix visual can partially achieved, but if you want to add two list in the matrix column, you should create a new table to custom the matrix. Here's my solution.

    1.Create a new table. Don't make relationship with other tables

    2.Create a measure.

    Measure =
    VAR _GrandTotal =
        COUNT ( 'departure data'[ID] )
    VAR _TotalPopulation =
        IF (
            ISINSCOPE ( 'departure data'[categorie] ),
            CALCULATE (
                COUNT ( 'total population'[ID] ),
                FILTER (
                    'total population',
                    'total population'[categorie] = MAX ( 'departure data'[categorie] )
                )
            ),
            COUNT ( 'total population'[ID] )
        )
    RETURN
        IF (
            MAX ( 'Table'[Column] )
                IN { "Discharge", "Lay-off", "Resignation", "Retirement" },
            CALCULATE (
                COUNT ( 'departure data'[ID] ),
                FILTER (
                    'departure data',
                    'departure data'[Leave reason] = MAX ( 'Table'[Column] )
                )
            ),
            SWITCH (
                MAX ( 'Table'[Column] ),
                "Grand Total", _GrandTotal,
                "Total population", _TotalPopulation,
                "%leave rate", FORMAT ( DIVIDE ( _GrandTotal, _TotalPopulation ), "#%" )
            )
        )
    

    Put Department and categorie column from departure data in the Matrix Rows, the new created Column in Matrix Columns, measure in Values, get the expected result:

    Notes:

    1.To sort in the expected layout, I add an index column in the new table, and sort the new column by Index.

    2.I uncheck the Blank option of the new column in the visual filter.

    3.In your total population table, Department D3 only contains category A and B, but C is not included.

    I attach my sample below for your reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

     

     

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    This is awesome!! Thank you for your time!

  • Hi Anonymous ,

    According to your description, Matrix visual can partially achieved, but if you want to add two list in the matrix column, you should create a new table to custom the matrix. Here's my solution.

    1.Create a new table. Don't make relationship with other tables

    2.Create a measure.

    Measure =
    VAR _GrandTotal =
        COUNT ( 'departure data'[ID] )
    VAR _TotalPopulation =
        IF (
            ISINSCOPE ( 'departure data'[categorie] ),
            CALCULATE (
                COUNT ( 'total population'[ID] ),
                FILTER (
                    'total population',
                    'total population'[categorie] = MAX ( 'departure data'[categorie] )
                )
            ),
            COUNT ( 'total population'[ID] )
        )
    RETURN
        IF (
            MAX ( 'Table'[Column] )
                IN { "Discharge", "Lay-off", "Resignation", "Retirement" },
            CALCULATE (
                COUNT ( 'departure data'[ID] ),
                FILTER (
                    'departure data',
                    'departure data'[Leave reason] = MAX ( 'Table'[Column] )
                )
            ),
            SWITCH (
                MAX ( 'Table'[Column] ),
                "Grand Total", _GrandTotal,
                "Total population", _TotalPopulation,
                "%leave rate", FORMAT ( DIVIDE ( _GrandTotal, _TotalPopulation ), "#%" )
            )
        )
    

    Put Department and categorie column from departure data in the Matrix Rows, the new created Column in Matrix Columns, measure in Values, get the expected result:

    Notes:

    1.To sort in the expected layout, I add an index column in the new table, and sort the new column by Index.

    2.I uncheck the Blank option of the new column in the visual filter.

    3.In your total population table, Department D3 only contains category A and B, but C is not included.

    I attach my sample below for your reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.