Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Calculated row in a matrix table

Hi,

I'm building my first Power BI dashboard but have spent hours trying to figure out how to do something with little success. 

I need to create a calculated row in a matrix table that gives the percentage of one specific row against another specific row. 

 

It needs to be laid out a little like this:

 

 Region 1Region 1Region 1Region 2Region 2

 

Country ACountry BCountry CCountry DCountry E
Profit     

Costs of Goods

     

Overheads

     

Interest

     
Tax     
Tax %     

 

The calculated row is the Tax % row which is Tax/Profit. No other calculations are needed. 

 

The table comes out perfectly using the matrix tool, but the tax percentage needs to be calculated by Power BI so that it changes every time I drill into something and change the filters etc. 

 

I have managed to create a 'measure' which correctly gives the result but I'm only able to put it in as either an extra set of columns or as a repeating row under every other row rather than just at the bottom. 

 

Any advice would be much appreciated. 

  • Hi Anonymous ,

     

    Please do like this.

     

    Measure = 
    VAR x = 
    SUMX(
        FILTER( Sheet5, [Column1] = "Profit" ),
        [Column4]
    )
    VAR y = 
    SUMX(
        FILTER( Sheet5, [Column1] = "Tax"),
        [Column4]
    )
    RETURN
    IF(
        HASONEFILTER([Column1B]),
        SUM([Column4]),
        DIVIDE( y, x, 0 )
    )

     

     

    Best regards,
    Lionel Chen

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

5 Replies

  • Hi,

    Profit, COGS, Overheads, Interest etc. should all be written as measures as well.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for the reply. 

       

      The problem is that there are a lot more rows than what I've shown and the rows are made up of three levels that I need to be able to drill into and out of. The matrix allows me to do that already but it might get complicated if I try to define everything with a separate measure. I could also have new rows come in at any point after creating the dashboard that the measures wouldn't account for. 

    • Anonymous's avatar
      Anonymous
      Not applicable

      @v-lionel-msft

      Thank you so much for this!

      I plugged it into my dashboard and it almost does exactly what I need to and it's my fault for missing out this bit of info.

      I also have multiple layers of rows. It looks like when I have just one level it works fine but bringing in more causes problems. I tried tweaking the measure using 'AND' but I couldn't quite get it to work.

      I have three levels of rows that I need to bring into the final matrix that can be expanded and collapsed. Column 1B is an example of an extra layer.

      Column1BColumn1Column2Column3Column4
      IncomeRevenueR1A100
      IncomeProfitR1B200
      IncomeProfitR1C300
      IncomeProfitR2D400
      IncomeProfitR2E500
      CostTaxR1A600
      CostTaxR1B700
      CostTaxR1C800
      CostTaxR2D900
      CostTaxR2E1000

      Any chance you could help me tweak it a little to work with the multiple rows too?

      Thank you so much again for your help!

      • v-lionel-msft's avatar
        v-lionel-msft
        Icon for Community Support rankCommunity Support

        Hi Anonymous ,

         

        Please do like this.

         

        Measure = 
        VAR x = 
        SUMX(
            FILTER( Sheet5, [Column1] = "Profit" ),
            [Column4]
        )
        VAR y = 
        SUMX(
            FILTER( Sheet5, [Column1] = "Tax"),
            [Column4]
        )
        RETURN
        IF(
            HASONEFILTER([Column1B]),
            SUM([Column4]),
            DIVIDE( y, x, 0 )
        )

         

         

        Best regards,
        Lionel Chen

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