Sum from other table when previous row is smaller than the following row

Hello again,

Kindly assist with this: I would like to sum sales when the previous row is smaller than the row below it.

2X_2_240e4035faa3a4f7e9f920f5a6b20dd83bbc743a.png
in the image attached, 3479 is smaller than the immediate row below it 5361 so the expression should calculate the sum.

Sum(SELECT(
Sales[Diesel Liter Sales],
[Timestamp] >= MAX(
SELECT(
Sales[Timestamp],
([Diesel Opening Dipstick] >[Most Recent].[Diesel Opening Dipstick] )))))

my expression is giving me an error of unable to find the column โ€œ[Diesel Opening Dipstick]โ€ of [Most Recent].[Diesel Opening Dipstick].
thanks.

0 7 432
7 REPLIES 7

Steve
Platinum 4
Platinum 4

Your request is unclear, but hereโ€™s something:

IFS(
  (
    LOOKUP(
      MAX(
        SELECT(
          Sales[_ROWNUMBER],
          ([_THISROW].[_ROWNUMBER] > [_ROWNUMBER])
        )
      ),
      "Sales",
      "_ROWNUMBER",
      "Diesel Liter Sales"
    )
    <
    [Diesel Liter Sales]
  ),
  (
    LOOKUP(
      MAX(
        SELECT(
          Sales[_ROWNUMBER],
          ([_THISROW].[_ROWNUMBER] > [_ROWNUMBER])
        )
      ),
      "Sales",
      "_ROWNUMBER",
      "Diesel Liter Sales"
    )
    +
    [Diesel Liter Sales]
  )
)

Hi Steve,
sorry for not being clear.

I am trying to sum all Diesel Liter Sales from Sales Table when the immediate row below value is higher than its above row value. The idea is I want to start summing when there is an increase in stock due to new delivery.

2X_8_8ad2778326e3a27c7384b80ff7371311e92f323c.png

the summing point of Diesel Liter Sales begins at the row that is parallel with the bigger value (5361) which is when the new stock arrives.

hope I make it clearer.

much thanks

Where would the answer be saved?

Hi Steve,
From your suggested expressions, I have temporarily got an accurate result by creating it in VC and a VC for the previous row that deducting the previous from the total sum.

the challenge is still to save in my Order Table and also stop the sum when a new immediate row below value is higher than its above row value.

IFS(
(
LOOKUP(
MAX(
SELECT(
Sales[_ROWNUMBER],
([_THISROW].[_ROWNUMBER] > [_ROWNUMBER])
)
),
โ€œSalesโ€,
โ€œ_ROWNUMBERโ€,
โ€œDiesel Liter Salesโ€
)
<
[Diesel Liter Sales]
),
(
LOOKUP(
MAX(
SELECT(
Sales[_ROWNUMBER],
([_THISROW].[_ROWNUMBER] > [_ROWNUMBER])
)
),
โ€œSalesโ€,
โ€œ_ROWNUMBERโ€,
โ€œDiesel Liter Salesโ€
)
+
Sum(Select(Sales[Diesel Liter Sales],[Timestamp]>=[_Thisrow].[Timestamp]))
)
)-[Previous Diesel Liter Sales]

While this looks like an interesting academic challenge, I donโ€™t see any good way to do what you want. I encourage you to consider alternative approaches.

I have another Table (Order[Diesel Liter Sales]

Thanks Steve for your time in itโ€ฆ I have considered doing it thru an automatic action. so that i could always check the new delivery if arrives and get the calculation immediately than looking for a needle in haystack. glad to practice though and squeezed drain my brain.

Top Labels in this Space