Forum Discussion

Domenico96's avatar
Domenico96
Icon for Helper I rankHelper I
7 months ago
Solved

Total in Matrix with values on row

Hello, 

I’m building a custom matrix for a client, and to display the values in rows, I created a custom measure. I couldn’t use the “Switch values to rows” option because it doesn’t export the data in the required layout.
I'm using a parameter to display the first colum, so it's dynamic. 


What I need to achieve is to have somenthing like this, so I can have the row " total " with the sum of every measure. 

 

Unfortunately the export in an excel file is necessary fot them, so I need to create a custom matrix. 

Every suggestion is helpful, thanks in advance for the support and help! 



  • danextian's avatar
    danextian
    7 months ago

    In one of my screenshots, I'm using a field parameter for the values. I have also attached a pbix in my initial reply, please refer to that. Otherwise, please provide a sanitized (confidential data removed)copy of your own pbix.

14 Replies

  • Hi Domenico96 ,

     

    You can still use the field parameter table but as a disconnected table. You also need to create another disconnected table for the row dimension you want to use that includes another row for total.

     

     

    As a dimension is now being used in the row headers instead of the measures, this should respect the current layout when experting from Power BI Service.

     

    Please see the attached pbix.

    • Domenico96's avatar
      Domenico96
      Icon for Helper I rankHelper I

      Hello danextian ,

      I think you're solution is going in the right way, but I'm using a parameter as L1, and for the values I'm using a switch. 
      So in matrix, my rows are, in order : 

      L1 = {
          ("Cliente", NAMEOF('Conto Economico'[Gruppo Clienti]), -1,"Cliente"),
          ("Committente", NAMEOF('Conto Economico'[Committente]), 0,"Committente"),
          ("Linea Economica", NAMEOF('Conto Economico'[Linea Economica]), -2,"Linea Economica"),
          ("Confezione", NAMEOF('Conto Economico'[Confezione]), 1,"Confezione"),
          ("Distretto", NAMEOF('Conto Economico'[Distretto]), 2,"Distretto"),
          ("Famiglia", NAMEOF('Conto Economico'[Famiglia]), 3,"Famiglia"),
          ("Gusto", NAMEOF('Conto Economico'[Gusto]), 4,"Gusto"),
          ("Imballo", NAMEOF('Conto Economico'[Imballo]), 5,"Imballo"),
          ("Marchio", NAMEOF('Conto Economico'[Marchio]), 6,"Marchio"),
          ("Mercato", NAMEOF('Conto Economico'[Mercato]), 7,"Mercato"),
          ("Ricetta", NAMEOF('Conto Economico'[Ricetta]), 8,"Ricetta"),
          ("Varietà", NAMEOF('Conto Economico'[Varietà]), 9,"Varietà"),
          ("Responsabile Vendite", NAMEOF('Conto Economico'[CM Resp Vendite.CM Resp Vendite Livello 01.Denominazione estesa]), 10,"Responsabile Vendite")
      }

      and 
      Facing Struttura =
      DATATABLE(
          "Voce facing", STRING,
          "Ordine", INTEGER,
          {
              {"Fatturato", 1},
              {"1° Margine Industriale", 2},
              {"2° Margine Industriale", 3},
              {"Margine Operativo Netto", 4},
              {"% Margine Operativo Netto", 5}
          }
      )

      How do I add the total in this structure ?
       


      • danextian's avatar
        danextian
        Icon for Super User rankSuper User

        Another AI slop that isn't even related to the question being asked.

    • Domenico96's avatar
      Domenico96
      Icon for Helper I rankHelper I

      I need to build a matrix with the values on row, as you can see I have a first level that is " Distretto " ( it's a parameter, so it's not fix but dynamic ) and then I have the measure I need : Fatturato, 1 Margine Industriale, 2 Margine Industriale, Margine Operativo Netto e % Margine operativo netto. 

      In order to achieve this result, I create a custom table to display this values on row, with this structure : 

      Facing Struttura =
      DATATABLE(
          "Voce facing", STRING,
          "Ordine", INTEGER,
          {
              {"Fatturato", 1},
              {"1° Margine Industriale", 2},
              {"2° Margine Industriale", 3},
              {"Margine Operativo Netto", 4},
              {"% Margine Operativo Netto", 5}
          }
      )

      and then added the measure. 

      What I need to achieve now is to have a "Total" row that sum up the total of every measure, like in the second screenshot I atteched earlier, but the default option of the matrix are not working as I need, so I need to create a workaround to display this solution. 
      Long story shot I need a total for every measure in a row called " total " .
      I hope now it more clear
      • cengizhanarslan's avatar
        cengizhanarslan
        Icon for Super User rankSuper User

        After reading this, I would suggest as below:

         

        1) Add a “Total” row to your Facing table

        Facing Struttura =
        DATATABLE(
            "Voce facing", STRING,
            "Ordine", INTEGER,
            {
                {"Fatturato", 1},
                {"1° Margine Industriale", 2},
                {"2° Margine Industriale", 3},
                {"Margine Operativo Netto", 4},
                {"% Margine Operativo Netto", 5},
                {"Total", 99}
            }
        )

        Sort [Voce facing] by [Ordine].

         

        2) Create your KPI measure (same as you already have)

        KPI Value =
        SWITCH(
            SELECTEDVALUE('Facing Struttura'[Voce facing]),
            "Fatturato", [Fatturato],
            "1° Margine Industriale", [MI1],
            "2° Margine Industriale", [MI2],
            "Margine Operativo Netto", [MON],
            "% Margine Operativo Netto", [%MON],
            BLANK()
        )

         

        3) Create the “KPI with Total row” measure

        KPI Value (with Total row) =
        VAR Voce = SELECTEDVALUE('Facing Struttura'[Voce facing])
        RETURN
        IF(
            Voce <> "Total",
            [KPI Value],
            [Fatturato] + [MI1] + [MI2] + [MON]
        )

         

         

  • Since you already have that matix I assuma you have required measues and a parameter to group those measures within different "Distretto"s.

     

    To properly return grand total in your visual I belive you could use the measure below:

     

    KPI Value (with Total) =
    VAR IsKpiRow =
        ISINSCOPE('KPI Param'[Name])
    RETURN
    IF(
        IsKpiRow,
        [KPI Value],
        SUMX(
            VALUES('KPI Param'[Name]),
            [KPI Value]
        )
    )
  • To let you better understand, this is how I created the matrix : 

    Rows (in this order, and I have a slicer to select the different dimension of the parameter) : 

    L1 = {
        ("Cliente", NAMEOF('Conto Economico'[Gruppo Clienti]), -1,"Cliente"),
        ("Committente", NAMEOF('Conto Economico'[Committente]), 0,"Committente"),
        ("Linea Economica", NAMEOF('Conto Economico'[Linea Economica]), -2,"Linea Economica"),
        ("Confezione", NAMEOF('Conto Economico'[Confezione]), 1,"Confezione"),
        ("Distretto", NAMEOF('Conto Economico'[Distretto]), 2,"Distretto"),
        ("Famiglia", NAMEOF('Conto Economico'[Famiglia]), 3,"Famiglia"),
        ("Gusto", NAMEOF('Conto Economico'[Gusto]), 4,"Gusto"),
        ("Imballo", NAMEOF('Conto Economico'[Imballo]), 5,"Imballo"),
        ("Marchio", NAMEOF('Conto Economico'[Marchio]), 6,"Marchio"),
        ("Mercato", NAMEOF('Conto Economico'[Mercato]), 7,"Mercato"),
        ("Ricetta", NAMEOF('Conto Economico'[Ricetta]), 8,"Ricetta"),
        ("Varietà", NAMEOF('Conto Economico'[Varietà]), 9,"Varietà"),
        ("Responsabile Vendite", NAMEOF('Conto Economico'[CM Resp Vendite.CM Resp Vendite Livello 01.Denominazione estesa]), 10,"Responsabile Vendite")
    }

    and 

    Facing Struttura =
    DATATABLE(
        "Voce facing", STRING,
        "Ordine", INTEGER,
        {
            {"Fatturato", 1},
            {"1° Margine Industriale", 2},
            {"2° Margine Industriale", 3},
            {"Margine Operativo Netto", 4},
            {"% Margine Operativo Netto", 5}
        }
    )

    Columns :
    Month
    and 
    ACT - PY - BDG - Delta =
    DATATABLE(
        "Voce Anno BDG", STRING,
        "Ordine", INTEGER,
        "Nome Pulito", STRING,
        {
            {"ACT", 1,"ACT"},
            {"PY", 2,"PY"},
            {"Delta ACT", 3,"ACT vs PY"}
        )

    VALUES : 
    Valori Facing Mensili =
    VAR Anno = SELECTEDVALUE('ACT - PY - BDG - Delta'[Nome Pulito])
    RETURN
    SWITCH(
        TRUE(),

        // Se Anno = ACT
        Anno = "ACT" && Misura = "Fatturato", FORMAT([Fatturato Mensile AC], "#,##0 €"),
        Anno = "ACT" && Misura = "1° Margine Industriale", FORMAT([1° Margine Industriale Mensile AC], "#,##0 €"),
        Anno = "ACT" && Misura = "2° Margine Industriale", FORMAT([2° Margine Industriale Mensile AC], "#,##0 €"),
        Anno = "ACT" && Misura = "Margine Operativo Netto", FORMAT([Margine Operativo Netto Mensile AC], "#,##0 €"),
        Anno = "ACT" && Misura = "% Margine Operativo Netto",
            IF(
                ISBLANK([% Margine Operativo Netto Mensile AC]),
                BLANK(),
                FORMAT([% Margine Operativo Netto Mensile AC] * 100, "0.00") & " %"
            ),

        // Se Anno = PY
        Anno = "PY" && Misura = "Fatturato", FORMAT([Fatturato Mensile AC PY], "#,##0 €"),
        Anno = "PY" && Misura = "1° Margine Industriale", FORMAT([1° Margine Industriale Mensile AC PY], "#,##0 €"),
        Anno = "PY" && Misura = "2° Margine Industriale", FORMAT([2° Margine Industriale Mensile AC PY], "#,##0 €"),
        Anno = "PY" && Misura = "Margine Operativo Netto", FORMAT([Margine Operativo Netto Mensile AC PY], "#,##0 €"),
        Anno = "PY" && Misura = "% Margine Operativo Netto",
            IF(
                ISBLANK([% Margine Operativo Netto Mensile AC PY]),
                BLANK(),
                FORMAT([% Margine Operativo Netto Mensile AC PY] * 100, "0.00") & " %"
            ),
     
            // Se Anno = ATC vs PY
        Anno = "ACT vs PY" && Misura = "Fatturato", FORMAT([Fatturato Mensile Delta PY],"#,##0  €"),
        Anno = "ACT vs PY" && Misura = "1° Margine Industriale", FORMAT([1° Margine Industriale Delta PY],"#,##0  €"),
        Anno = "ACT vs PY" && Misura = "2° Margine Industriale", FORMAT([2° Margine Industriale Delta PY],"#,##0  €"),
        Anno = "ACT vs PY" && Misura = "Margine Operativo Netto", FORMAT([Margine Operativo Netto Delta PY],"#,##0  €"),
        Anno = "ACT vs PY" && Misura = "% Margine Operativo Netto",
            IF(
                ISBLANK([% Margine Operativo Netto Delta PY]),
                BLANK(),
                FORMAT([% Margine Operativo Netto Delta PY] * 100, "0.00") & " %"
            ),
    BLANK()
    )

    I need to have another level or another way to display the even the row " Total " with the different measure aggregated, like the second screenshot in the original question

    For example, this is the result I want when selecting December and "Act"