How can I reduce the formula?

Hello, I want to take data from a user, it has to be the last data.
I created this, and it works, but I donโ€™t want to do something so complex because I need to use it many times:

IF([_THISROW].[MES DEVENGADO]<12,

SUM(SELECT(LIQUIDAR_UNIDAD[ADEUDA FO],
AND(
[ID_UNIDAD]=[_THISROW].[ID_UNIDAD],
[Aร‘O DEVENGADO]=[_THISROW].[Aร‘O DEVENGADO],
[MES DEVENGADO]=[_THISROW].[MES DEVENGADO]-1
)
)),

SUM(SELECT(LIQUIDAR_UNIDAD[ADEUDA FO],
AND(
[ID_UNIDAD]=[_THISROW].[ID_UNIDAD],
[Aร‘O DEVENGADO]=[_THISROW].[Aร‘O DEVENGADO]-1,
[MES DEVENGADO]=[_THISROW].[MES DEVENGADO]
)
))

)

0 6 139
6 REPLIES 6

Have you tried [_ThisRow].[_RowNumber]-1

can you please explain your requirement a little bit more in words because with the lengthy formula I couldnโ€™t figure out your exact requirement.

There is probably a better way of writing it depending on the exact requirements, but if you just want to reduce the size of the expression then the following should do the same:

SUM(
  SELECT(
    LIQUIDAR_UNIDAD[ADEUDA FO],
    AND(
      [ID_UNIDAD]=[_THISROW].[ID_UNIDAD],
      [Aร‘O DEVENGADO]=[_THISROW].[Aร‘O DEVENGADO]
        - IF([_THISROW].[MES DEVENGADO]<12,0,1),
      [MES DEVENGADO]=[_THISROW].[MES DEVENGADO]
        - IF([_THISROW].[MES DEVENGADO]<12,1,0)
    )
  )
)

Thinking about this a little more, I assume MES stands for month and therefore can only have a value of 1 to 12. If that is the case then we should be able to use some math functions to completely remove the conditional operation.

SUM(
  SELECT(
    LIQUIDAR_UNIDAD[ADEUDA FO],
    AND(
      [ID_UNIDAD]=[_THISROW].[ID_UNIDAD],
      [Aร‘O DEVENGADO]=[_THISROW].[Aร‘O DEVENGADO]
        - FLOOR([_THISROW].[MES DEVENGADO] / 12),
      [MES DEVENGADO]=[_THISROW].[MES DEVENGADO]
        - (1 - FLOOR([_THISROW].[MES DEVENGADO] / 12))
    )
  )
)

Thanks, I am going to test it.

Steve
Platinum 5
Platinum 5

My take:

SUM(
  SELECT(
    LIQUIDAR_UNIDAD[ADEUDA FO],
    AND(
      ([ID_UNIDAD] = [_THISROW].[ID_UNIDAD]),
      IF(
        ([_THISROW].[MES DEVENGADO] < 12),
        AND(
          ([Aร‘O DEVENGADO] = [_THISROW].[Aร‘O DEVENGADO]),
          ([MES DEVENGADO] = ([_THISROW].[MES DEVENGADO] - 1))
        ),
        AND(
          ([Aร‘O DEVENGADO] = ([_THISROW].[Aร‘O DEVENGADO] - 1)),
          ([MES DEVENGADO]=[_THISROW].[MES DEVENGADO])
        )
      )
    )
  )
)

Please explain.

Hello, thank you all for your answers.
I am passionate about Excel and I loved this AppSheet initiative.

I made an application that manages the common expenses of buildings in horizontal property. In this cell I want it to take the data of the previous month and add it, in case we are in December it will take the last date of the previous year.

Iโ€™m half dyslexic, so I just realized that instead of 12 it should have been month 1 haha, so Iโ€™m not going to use the answers but Iโ€™m still working with your input thanks.

It has been quite complex and I think that is why there are sheets to which I can not filter, for this reason, I think that reducing the code will be a solution.

Best!!

Top Labels in this Space