Forum Discussion

MauricioSD's avatar
MauricioSD
Helper I
4 years ago
Solved

Calculate field in row header

Hi All.   I need make a "pivot table" in Power BI, but the info need 3 "measure fields", this are: % SVM % Op. Margin % EBT   But, when i make this measures, y can put in row header in a table...
  • PaulDBrown's avatar
    PaulDBrown
    4 years ago

    Ok, first of all, make ysure you Trim and clean the P&L structure field in the table (Power Query).

    Then create a new table either in Power Query or using Dax for the row. I've created it using:

    P&L Rows = 
    {("Sales", 1),
    ("SVC", 2),
    ("DSC", 3),
    ("SVM", 4),
    ("% SVM", 5),
    ("OVC", 6),
    ("CC", 7),
    ("Other Expenses", 8),
    ("Op. Margin", 9),
    ("% Op. Margin", 10),
    ("NOR", 11),
    ("EBT", 12),
    ("% EBT", 13),
    ("Income Taxes", 14),
    ("Net Income", 15)}

     

    Join this table with the Main table in an inactive relationship. I've also created dimension Tables for Period and Amount Type. The model looks like this:

    Now the measures... Firstly, the main measure:

    Sum Amount =
    CALCULATE (
        SUM ( FTable[ Amount ] ),
        USERELATIONSHIP ( 'P&L Rows'[Structure], FTable[ PL_Structure ] )
    )
    

    Then the measures for the %:

    % SVM =
    VAR _Sales =
        CALCULATE (
            [Sum Amount],
            FILTER ( ALL ( 'P&L Rows' ), 'P&L Rows'[Structure] = "Sales" )
        )
    VAR _SVM =
        CALCULATE (
            [Sum Amount],
            FILTER ( ALL ( 'P&L Rows' ), 'P&L Rows'[Structure] = "SVM" )
        )
    RETURN
        DIVIDE ( _SVM, _Sales )
    
    % Op. Margin =
    VAR _Sales =
        CALCULATE (
            [Sum Amount],
            FILTER ( ALL ( 'P&L Rows' ), 'P&L Rows'[Structure] = "Sales" )
        )
    VAR _OM =
        CALCULATE (
            [Sum Amount],
            FILTER ( ALL ( 'P&L Rows' ), 'P&L Rows'[Structure] = "Op. Margin" )
        )
    RETURN
        DIVIDE ( _OM, _Sales )
    
    % EBT =
    VAR _Sales =
        CALCULATE (
            [Sum Amount],
            FILTER ( ALL ( 'P&L Rows' ), 'P&L Rows'[Structure] = "Sales" )
        )
    VAR _EBT =
        CALCULATE (
            [Sum Amount],
            FILTER ( ALL ( 'P&L Rows' ), 'P&L Rows'[Structure] = "EBT" )
        )
    RETURN
        DIVIDE ( _EBT, _Sales )
    

    Now the final measure for the matrix visual:

    Table value =
    SWITCH (
        SELECTEDVALUE ( 'P&L Rows'[Order] ),
        5, FORMAT ( [% SVM], "Percent" ),
        10, FORMAT ( [% Op. Margin], "Percent" ),
        13, FORMAT ( [% EBT], "Percent" ),
        [Sum Amount]
    )
    

    Now you can create the matrix visual using the P&L [Structure] field as rows, the Typ_amount fromt he dimension table as the columns and the [Table Value] as the value to get:

    If you want to colour the row headers as your example, you need to use a table visual and split the [Table Value] measure into Actual and Plan following this pattern:

    _Actual =
    CALCULATE ( [Table value], 'Type'[Type_Amount] = "Actual" )
    

     

    I've attached the sample PBIX file