How to create a Virtual Column with the sum of values of a Column in another Table?

cboteros
Participant III

Hello everyone,

I hope someone can help me with this.

I have a table “EXPENSES” which have a Column “Date” and another column “Amount”.

I have also another table “PERIOD” which has a column “Month” (which is the 1st day of every month) and I want to create a Virtual Column which will be “Expenses Sum within the Month”.

So, in pseudo code, I want to have:

SUM (
EXPENSE[Amount],
IF (EXPENSE[Date] >= PERIOD[Month] AND EXPENSE[Date] < EOMONTH(PERIOD[Month],1)
)

As I understand, since “SUMIF” doesn’t exist, I need to use SUM(SELECT(…) ), but I’m not able to create such SELECT(…)

I’ve tried:

SELECT(
EXPENSES[Amount],
AND(
EXPENSES[Date] >= PERIOD[Month],
EXPENSES[Date] < EOMONTH(PERIOD[Month],1
)
)

But I don’t seem to succeed… Anyone knows what could I be doing wrong?

Thank you!

Carlos B.

0 2 588
2 REPLIES 2

Expression of the form Table[Column] will return a List type of ALL values in “Column” for the entire “Table”.

So, when you write EXPENSES[Date] and PERIOD[Month] , you’re getting 2 Lists of Date types, not single Dates.

Your condition expressions within the SELECT() should instead be:
[Date] >= [_THISROW].[Month]
[Date] < EOMONTH( [_THISROW].[Month] , 1 )

Since you’re running SELECT() on the EXPENSES table, you are already in the context of each individual EXPENSE record (iteratively), so you just call the columns by name within square brackets. And since you’re running it from the PERIOD table, so you need to use [_THISROW]. to first “de-reference” the current record in the PERIOD table.


Additionally, I think you can get rid of the AND(), and only use one condition in your SELECT, as follows, but make sure you test it.
MONTH( [Date] ) = MONTH( [_THISROW].[Month] )

Steve
Participant V

For reference:

Top Labels in this Space