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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
michellepace
Resolver III
Resolver III

Dax formula to do a lookup/related in another table

Hello,

I am at the beginning of my Dax learning curve and really struggling. I'm importing accounting transactional data where income is postive and expenses are negative. So far I have this formula which works fine:

 

Actuals = SUM( 'Account Transactions'[Amount] )

 

Now, I'd like to represent my negtaive values as postive numbers in my matrix as well as graphs. If I write it in psudeo code, this is what it looks like:

 

Actuals_ForMatrix&Graphs = 

var isExpense = if([IncomeExpense]="Expense", true, false) **need help here!

return if (isExpense, [Actuals] * -1, [Actuals])

 

p.png 

 

Can anyone please help me write the dax I need?

1 ACCEPTED SOLUTION

@michellepace 

Try this measure:

You mentioned + into - and the other way is required in the comment but your measure tries to do the following leaving Income as it is.

Actuals_ForMatrix&Graphs = 

SUMX(
    'Account Transactions',

    IF(
        RELATED('Account Categories'[IncomeExpense]) = "Expense",
        [Actuals] * -1,
        [Actuals]
    )
)



________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

8 REPLIES 8
Fowmy
Super User
Super User

@michellepace 

Try

 

 = ABS([Actuals])

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi @Fowmy, thank you for your reply. I'm afraid it is not as simple as wrapping with an ABS function. For my expenses, I need to change positive values to negative values and negative values to positive values. To wrap it with an ABS function would throw my numbers out. For example, you can incur an expense when buying 100 boxes but then ask your supplier for a credit note for 20 of thos boxes. I really need to do as I say, multiple by (-1) for every ledger transactional line where [IncomeExpense]="Expense".

Also, I'm really keen to wrap my head around this little piece of dax, I'm hoping it will help in my undrestanding. Surely it cannot be that difficult? It's pretty simple in exel 🙂 

@michellepace 

Try this measure:

You mentioned + into - and the other way is required in the comment but your measure tries to do the following leaving Income as it is.

Actuals_ForMatrix&Graphs = 

SUMX(
    'Account Transactions',

    IF(
        RELATED('Account Categories'[IncomeExpense]) = "Expense",
        [Actuals] * -1,
        [Actuals]
    )
)



________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you @Fowmy !! It's so simple when you know how :). Thanks very much, exactly what I was looking for. 

I figured out another way to achieve the same thing using PowerQuery editor. I merged the IncomeExpense column from table AccountCategories into the table AccountTransactions. Then I created a conditional column using: 

 

= Table.AddColumn(#"Expanded Account Categories", "Amount(+)", each if [Account Categories.IncomeExpense] = "Expense" then [Amount]*-1 else [Amount])

 

My Last Question:
In terms of performance, is there a preferable way and which is best? Using dax as you've shown, or doing it with Power Query (for example, is one better for performance than another)?

@michellepace 

Glad it worked for you!

It is better to keep it with DAX it is more on the calculation side. When you do in PQ, it adds additional data load and it is static.

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@michellepace , Try like ?

if( [IncomeExpense]="Expense",-1*[Actuals] ,[Actuals] )

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak , please take a look at my original question. [IncomeExpense] is not a measure I have defined. That is the problem. I don't know how to look up a value. Please read my question and let me know your thoughts?

Greg_Deckler
Super User
Super User

@michellepace - You should just be able to wrap your calculation with ABS function



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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