Forum Discussion

Clara's avatar
Clara
Advocate II
7 years ago
Solved

Aggregate differently by category

Let's say I have dozens of store units for which I have Revenue, Profit and Profitability values for each month since January 2016 (date format is DD/MM/YYYY):

 

UnitTypeDateValue
AARevenue01/01/20161288000
AARevenue01/02/20161335900
AARevenue01/03/20162133400
AARevenue01/04/20162564000
........
AARevenue01/05/20182799900
AARevenue01/06/20181164000
AARevenue01/07/20182291900
AARevenue01/08/20182297000
AARevenue01/09/20181715900
AAProfit01/01/2016166900
AAProfit01/02/2016-30600
AAProfit01/03/2016934100
AAProfit01/04/20161111200
........
AAProfit01/05/20181649600
AAProfit01/06/201871000
AAProfit01/07/2018965600
AAProfit01/08/2018632000
AAProfit01/09/2018-2600
AAProfitability01/01/201613%
AAProfitability01/02/2016-2%
AAProfitability01/03/201644%
AAProfitability01/04/201643%
........
AAProfitability01/05/201859%
AAProfitability01/06/20186%
AAProfitability01/07/201842%
AAProfitability01/08/201828%
AAProfitability01/09/2018-0,2%
BBRevenue01/01/20161454000
........

 

My report has a slicer for Unit. I want to create a matrix visual that would show Revenue, Profit and Profitability for each unit across years (note that Revenue and Profit are sums of values for all months within the year, while Profitability is simply Profit/Revenue). Selecting Unit = AA, the visual would show:

 

 201620172018
Revenue21963900..24644880
Profit6544800..3315600
Profitability30%..13%

 

(The above matrix is the result I want.)

 

However, when I create the visual in Power BI it aggregates all values by Sum and returns:

 

 201620172018
Revenue21963900..24644880
Profit6544800..3315600
Profitability358%..161%

 

Therefore, while the first two are correct, Profitability isn't.

Were I to aggregate values by Average, Profitability would be correct* and the other two wouldn't.

 

Is there any way I can aggregate Revenue and Profit by Sum, while aggregating Profitability by Average, all in the same visual?

 

* Note that for 2018, given the way my original data is designed, Profitability wouldn't be correct simply aggregated by Average, since October, November and December/2018 currently have null values which would affect the average. It would be best to be able to aggregate Profitability by average while ignoring zeros.

  • Anonymous's avatar
    Anonymous
    7 years ago

    Hi Clara,

     

     

    Yes there is.

    You will need a measure though, like this one:

     

    Value measure = IF (
            FIRSTNONBLANK ( Table1[Type], 1 ) = "Profitability",
            AVERAGE ( 'Table1'[Value] ) ,
            CALCULATE (
                SUMX (Table1,('Table1'[Value])
                )
            )
        )

    Instead of adding the value column as the value in matrix, use the Value measure instead.

     

    It gives this result:

     

    Note that the calculation is not correct. I just used your sample to have some test data.

     

    Best regards

    Kaj

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Clara,

     

     

    Yes there is.

    You will need a measure though, like this one:

     

    Value measure = IF (
            FIRSTNONBLANK ( Table1[Type], 1 ) = "Profitability",
            AVERAGE ( 'Table1'[Value] ) ,
            CALCULATE (
                SUMX (Table1,('Table1'[Value])
                )
            )
        )

    Instead of adding the value column as the value in matrix, use the Value measure instead.

     

    It gives this result:

     

    Note that the calculation is not correct. I just used your sample to have some test data.

     

    Best regards

    Kaj

    • Clara's avatar
      Clara
      Advocate II

      Anonymous Thank you so much! I've made one slight modification to your measure so as to ignore null values in the average, and got exactly what I wanted:

       

       

      Value measure = IF (
              FIRSTNONBLANK ( Table1[Type], 1 ) = "Profitability",
              CALCULATE ( AVERAGE ('Table1'[Value]), FILTER('Table1', 'Table1'[Value]<>0) ),
              CALCULATE (
                  SUMX (Table1,('Table1'[Value])
                  )
              )
          )

       

       

      • Anonymous's avatar
        Anonymous
        Not applicable
        You're most welcome! Glad I could help :)