Forum Discussion

Pillic's avatar
Pillic
Icon for Helper II rankHelper II
4 years ago
Solved

ADD calculated Average to each row

Hello comunity,

 

I have a simple table that looks like this:

delivery | product | price | r price      

1011084259 10096246 3750,7
1011085643 10096246 3744,1
1011260543 10096246 3755,2
1011369349 10096246 3742
1011684236 10089222 2563,7
1011675242 10096246 3746,9
1011677098 10096246 3748,2
1011723460 10096246 3745,2

 

The average of column price is 35,5 = average(table[price])

Now I want to sum the average of price to each row of r price
 
delivery | product | price | r price  | r price + average price
1011084259 10096246 37

50,7

86,2
1011085643 10096246 3744,179,6
1011260543 10096246 3755,290,7
1011369349 10096246 374277,5
1011684236 10089222 2563,799,2
1011675242 10096246 3746,982,4
1011677098 10096246 3748,283,7
1011723460 10096246 3745,280,7

 

The following measure doesnt work...it sums each price to r price per row. 

VAR x = average(table[price])
RETURN CALCULATE(SUM (table[r price]) + x)

It would be great if this could be solved.

Thanks in Advance
  • Hey,

     

    Try this:

    r price + average = 
    VAR r_price =
        SUM ( 'table'[r price] )
    VAR r_price_average =
        CALCULATE ( AVERAGE ( 'table'[r price] ), ALLSELECTED () )
    RETURN
        r_price + r_price_average

4 Replies

  • Barthel's avatar
    Barthel
    Icon for Solution Sage rankSolution Sage

    Hey,

     

    Try this:

    r price + average = 
    VAR r_price =
        SUM ( 'table'[r price] )
    VAR r_price_average =
        CALCULATE ( AVERAGE ( 'table'[r price] ), ALLSELECTED () )
    RETURN
        r_price + r_price_average
    • Pillic's avatar
      Pillic
      Icon for Helper II rankHelper II

      Hello Barthel,

       

      amazing that did the job. I needed to change it a bit like this:

      r price + average = 
      VAR r_price =
          SUM ( 'table'[r price] )
      VAR price_average =
          CALCULATE ( AVERAGE ( 'table'[price] ), ALLSELECTED () )
      RETURN
          r_price + r_price_average

       

      Thanks a ton for this fast response...Yall have a nice weekend, as I will now.

  • tamerj1's avatar
    tamerj1
    Icon for Community Champion rankCommunity Champion

    Hi Pillic 
    You can do the following 

    r price + average price = 
    VAR AveragePrice = 
        CALCULATE ( AVERAGE ( Data[price] ), ALLSELECTED ( ) )
    RETURN
        SUMX (
            Data,
            Data[r price] + AveragePrice
        )
    • Pillic's avatar
      Pillic
      Icon for Helper II rankHelper II

      Hi tamerj1 ,

       

      thanks, this provided measure is much faster if I use it with unfiltered content. Awesome. Thx