Forum Discussion
using switch to evaluate reversal entries
Hi,
I have the following dataset. I want to be able to add a column after to label each row as to whether it is a reversal entry or not.
| Vendor ID.# | Name | Invoice No.# | Transaction Amount |
| 600754 | aaaa | 123 | 366 |
| 989111 | bbbb | 234 | 320 |
| 242001 | cccc | 86030 | 242 |
| 242001 | cccc | 86030 | -242 |
I tried using the switch formula like this:
Hi adbm -Can you please try the below calculated column,it's returning multiple rows when it needs a scalar.
check the calculated column
IsReversal =
VAR CurrentInvoice = 'Vendor data'[Invoice No.#]
VAR CurrentAmount = 'Vendor data'[Transaction Amount]
RETURN
IF(
CALCULATE(
COUNTROWS('Vendor data'),
FILTER(
'Vendor data',
'Vendor data'[Invoice No.#] = CurrentInvoice &&
'Vendor data'[Transaction Amount] = -CurrentAmount
)
) > 0,
"Reversal",
"Not Reversal"
)Hope we will not an error. it works.
5 Replies
- rajendraongole1
Super User
Hi adbm -Can you please try the below calculated column,it's returning multiple rows when it needs a scalar.
check the calculated column
IsReversal =
VAR CurrentInvoice = 'Vendor data'[Invoice No.#]
VAR CurrentAmount = 'Vendor data'[Transaction Amount]
RETURN
IF(
CALCULATE(
COUNTROWS('Vendor data'),
FILTER(
'Vendor data',
'Vendor data'[Invoice No.#] = CurrentInvoice &&
'Vendor data'[Transaction Amount] = -CurrentAmount
)
) > 0,
"Reversal",
"Not Reversal"
)Hope we will not an error. it works.
- adbm
Helper I
Hi rajendraongole1 - could you please briefly explain how your formula works but my switch one didnt? i guess its a matter of learning DAX but if you could please explain a bit right now, ill know which direction to head in the next time.
- rajendraongole1
Super User
Hi adbm - Glad it works at your end. Filter is being used incorrectly in the context of the switch statement, as it's returning multiple rows when it needs a scalar (single value).the logic you want have to be implemented using calculate and filter, which will allow you to check for reversal entries row by row.Let me know if any information required from my end/
Hope the above information helps.
- bhanu_gautam
Super User
adbm , Try using below measure
IsReversal =
VAR CurrentInvoice = 'Vendor data'[Invoice No.#]
VAR CurrentAmount = 'Vendor data'[Transaction Amount]
RETURN
IF (
CALCULATE (
COUNTROWS('Vendor data'),
'Vendor data'[Invoice No.#] = CurrentInvoice,
'Vendor data'[Transaction Amount] = -CurrentAmount
) > 0,
"Reversal",
"Not Reversal"
) - adbm
Helper I
Thanks rajendraongole1 - this worked.