Forum Discussion

benjos23's avatar
benjos23
Helper I
1 year ago
Solved

Hide effectively sublevel in matrix

Hi !

I am currently creating an Income Statement, and I am having some performance issues with my central table. To give some context, I have a fact table, which contains all the entries, each linked to a specific account, a table which contains all the indicator names, with a unique identifier, and a table which contains all the accounts, each linked to a specific indicator.
Entry :

Date  AccountNo  Amount  Type (ACT or BGT)

KPIDim :

IdNamePosition

AccountDim :

NoNameKPIId

 

The relationships are as follows:
KPIDim[Id] -> AccountDim[KPIId]
AccountDim[No] -> Entry[AccountNo]


Then, I created a measure for each indicator. Some of them use the KPIId column of the AccountDim table directly, and others, like gross margin for example, simply aggregate the measure of other indicators.
ActualSales = CALCULATE(SUM(Entry[Amount]), Entry[Type]="ACT", KPIDim[Id]="sales")
ActualCosts = CALCULATE(SUM(Entry[Amount]), Entry[Type]="ACT", KPIDim[Id]="costs")
ActualMargin = [ActualSales] - [ActualCosts]
With a final measure that selects the correct indicator, with a switch case:
SelectedIndicator = SWITCH(SELECTEDVALUE(KPIDim[Id],

                                              "sales", ActualSales,

                                              "costs", ActualCosts,

                                              "margin", ActualMargin,
                                              BLANK())

 

The table I want to create uses PowerBI's Matrix visual and contains: 

Rows:

  1. Name of indicator (e.g. sales or gross margin)
  2. Account the indicator contains

Columns:

  1. Month

Values :

  1. Actual amount
  2. Budgeted amount

The question I'm now asking myself is how to get the table to display the accounts (sub-level) under the indicator ONLY if it contains them directly. This would be the case for sales and costs, but not for gross profit. So we'd need a table like this (here only the actual value is displayed):

 January  February  March 
Sales101215

  Account A

677

  Account B

458

 

   

Costs

357

  Account C

134

  Account D

223

 

   

Gross margin  

77

8


But for now, the result is as follows:

 January  February  March 
Sales101215

  Account A

677

  Account B

458

 

   

Costs

357

  Account C

134

  Account D

223

 

   

Gross margin  

77

8

  Account A

677

  Account B

458

  Account C

134

  Account D

223

 

I've managed to achieve this result by using a calculation group, which forces the accounts to be hidden for certain indicators, but the table is very slow to refresh when I select another year. The elements of the calculation group are as follows:

Hide =
IF(
    HASONEVALUE(AccountDim[No]) &&
    SELECTEDVALUE(KPIs[Id]) IN {"grossSales", "netSales", "materialLoad", "inventoryChange", "merchandiseLoad", "margin", "margin2", "ebitda", "ebit", "operatingIncome", "netIncomeAfterTax", "cashflow" },
    BLANK(),
    SELECTEDMEASURE()
)

So I've come here to ask your opinion on this technique, and if of course you have any cleaner, better suggestions. To give a better idea, I'd like to do the same thing as in this YouTube tutorial: (64) The anatomy of an income statement matrix in Power BI - YouTube
 
Thank you in advance for your help 🙂
  • I think the main issue explaining why the refresh of my matrix was so slow, is that I computed measures that were "imbricated". I completely reshaped my model, so that the rules for computing my indicators are applied in columns of an AccountDim table. Then, by setting the correct relationships, the matrix is easy to build and performances are great !

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  benjos23 ,

     

    You can try the following measure:

    Hide =
    var _column=
    {"grossSales", "netSales", "materialLoad", "inventoryChange", "merchandiseLoad", "margin", "margin2", "ebitda", "ebit", "operatingIncome", "netIncomeAfterTax", "cashflow" }
    var _table=
    SUMMARIZE(ALL('AccountDim'),[Name of indicator],[Account the indicator contains],[Id],[Month],"Value_True",SUMX(FILTER('AccountDim',NOT('AccountDim'[Id]) in _column),[Value])
    )
    return
    IF(
        HASONEVALUE('AccountDim'[Account the indicator contains]) ,
      SUMX(
          FILTER(_table,[Name of indicator]=MAX([Name of indicator])&&[Account the indicator contains]=MAX([Account the indicator contains])&&[Month]=MAX([Month])),[Value_True])
        ,
    IF(
        HASONEVALUE('AccountDim'[Name of indicator])&&NOT(HASONEVALUE('AccountDim'[Account the indicator contains])),SUM('AccountDim'[Value]),BLANK())  
    )

     

    If the dax above doesn't meet your expectations, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

     

    Best Regards,

    Liu Yang

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

  • Hey Anonymous,
    Thank you for your answer.
    Actually, the model you created does not really look like to what I gave in my message, but I have the feeling the idea behind the solution you provided is the same as mine. I think I will stick to the method I have found, even if it is not very fast... I don't really find any other solution here, unfortunately.

  • I think the main issue explaining why the refresh of my matrix was so slow, is that I computed measures that were "imbricated". I completely reshaped my model, so that the rules for computing my indicators are applied in columns of an AccountDim table. Then, by setting the correct relationships, the matrix is easy to build and performances are great !