Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Exclude current row from calculation

Hi. I need to do the following. I have a table of, say, products sold. Each row shows the selling price. It also shows the profit (selling price minus cost.) The bottom of the table shows the total profit % (gross profit %). That's the total profit divided by the total revenue (selling price). The table also shows the the GP% for each individual row. What I now need is to add another column to show what the total GP% would be if i were to exclude the current row from the sales transactions. Is there a way to accomplish this and at any level of granularity?

itemRevenue GP$ GP%Total GP% without current item
item1        1,000            90090.0%54%
item2        2,000        1,20060.0%60%
item3        3,000        1,50050.0%70%
Total GP%  60% 

11 Replies

  • Anonymous 
    Is this a Table Visual or a table in the model?
    Are Revenue and GP$ are measures or columns? 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks @Fowmy  GP$ is going to be a simple measure: revenue - cost. Revenue is a column. It's a visual. Also, I'm trying to make this solution work at any granularity. For instance, if, say, I have multiple aggregation levels, like, product segment that has many items. What will the result be if i were to drill up to the product segment? And, say, now there is even one more level, say, salesperson that has many segments, what will the result at that level? Thanks!

    • Anonymous's avatar
      Anonymous
      Not applicable

      Fowmy  and Anonymous . I kind of got something working there. I'm yet to test it for multiple granularity levels. However, as you can see from the screen grab, the total at the bottom of GP_Impact% is wrong. The way I got it to work so far is by doing the calculation for avery row twice--once using the all() function and another without it and then dividing the two.

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks Fowmy  GP$ is going to be a simple measure: revenue - cost. Revenue is a column. It's a visual. 

  • Anonymous's avatar
    Anonymous
    Not applicable

    You could try:

    ExCurrentRow = let tbl = PriorStepName, ThisItem = each [ItemID],
    Ex = Table.SelectRows(tbl, each [ItemID] <> ThisItem),
    RevEx = List.Sum(Ex[Revenue]),

    GPEx = List.Sum(Ex[GP$])

    in

    Table.AddColumn(PriorStepName, "GPExCurrentRow", each GPEx / RevEx)

     

    --Nate

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Anonymous . Your solution seems to be using M Query. I need this to work at the visual level. Thanks so much for your response.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks v-lionel-msft. I'm away from work now. I will review and will get back to you by the end of the week.

  • v-lionel-msft's avatar
    v-lionel-msft
    Community Support

    Hi Anonymous ,

     

    Has your problem been solved?

     

    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.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, v-lionel-msft . Sorry, I noted below that I am on vacation. I can't actually verify right now because I do not have the work laptop. I promise to verify and let you know by the end of the weekend. Thank you so much for your caring.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, v-lionel-msft . Thanks so much. Your solution works. However, it works at one level only. I needed it to work for each level in the hierarchy as in the below table. Thanks so much for your efforts!