Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Calculated Column

Hi All, 

 

I have a dataset with a Transactions Table, I want to create a caculated column that checks for a TransactionType using the TansactionType ID Column and then returns a value based off a calculation on the Amount Column.

 

For example:

If TransactionType is 1, Return amount in Amount Column multiplied by 2

If TransactionType is 2, Return amount in Amount Column.

If TransactionType is 15, Return amount in amount table minus 500.

 

WhatsApp Image 2020-06-24 at 4.21.56 PM.jpeg

 

So bascially, I want a Calculated Column thats checks for a transactionID, and returns a calulation on the Amount Column.

 

Any help would be appreciated.

3 REPLIES 3
AntrikshSharma
Super User
Super User

Try something like this.

 

Transaction Amount =
VAR TransactionID = Transaction[TansactionType ID]
VAR TransactionAmount = Transaction[Amount]
VAR ReturnAmount =
    SWITCH (
        TRUE (),
        TransactionID = 1, TransactionAmount * 2,
        TransactionID = 2, TransactionAmount,
        TransactionID = 15, TransactionAmount - 500,
        0
    )
RETURN
    Result
Anonymous
Not applicable

I tried this syntax:

 

Revenue =
VAR TransactionID = Transactions[TransactionTypeId]
VAR TransactionAmount = Transactions[Amount($)]
VAR ReturnAmount =
SWITCH(
TRUE(),
TransactionID = 1, TransactionAmount,
TransactionID = 2, 6 * 360.5,
TransactionID = 72, TransactionAmount,
TransactionID = 4, 0,
TransactionID = 5, TransactionAmount,
TransactionID = 12, 0,
TransactionID = 49, TransactionAmount * 0.65,
TransactionID = 66, TransactionAmount,
TransactionID = 68, TransactionAmount,
TransactionID = 69, TransactionAmount,
TransactionID = 67, TransactionAmount,
TransactionID = 35, TransactionAmount - 500,
0
)
RETURN
Result
 
 
But still returns an error message. Please what do i define inside of the RETURN function

HI @Anonymous ,

 

You code is okay.

You need to return Return Amount

 

Better Formatted Code

 

Revenue =
VAR TransactionID = Transactions[TransactionTypeId]
VAR TransactionAmount = Transactions[Amount($)]
VAR ReturnAmount =
    SWITCH (
        TRUE (),
        TransactionID = 1
            || TransactionID = 5
            || TransactionID = 72
            || TransactionID = 66
            || TransactionID = 68
            || TransactionID = 69
            || TransactionID = 67, TransactionAmount,
        TransactionID = 2, 6 * 360.5,
        TransactionID = 49, TransactionAmount * 0.65,
        TransactionID = 35, TransactionAmount - 500,
        0
    )
RETURN
    ReturnAmount

 

 

Regards,

Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.