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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
MichelBrown
Regular Visitor

Measure combining two related tables with if then logic sought

Hello all, 

Can anyone help me with the following:

I have a fact table with (simplified) many rows with account number and amount.

And a dimension table with account number, description and DebetCredit indicator

In the fact table amounts are negative on a row with a (related) credit account and positive on a row with a (related) debet account.

For the sake of graphs, I want to change the credit / negative amounts into positive amounts. My question is how to do this with a DAX measure?

My thinking was something like this:

VAR multiplier = If (RELATED(dim_Accounts[DebitCredit])="Credit";-1;1)

RETURN

Sum(fact_SAP[Amount]) * multiplier

 

But this turns out to be wrong in such a way that even the help error text doesn't help me to find a solution. My gut feeling says I have to use RELATED or maybe even RELATEDTABLE ?? and maybe something like SUMX but I can't figure it out.

 

Thanks in advance for any support.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@MichelBrown , try like

 

calculate(-1*Sum(fact_SAP[Amount]),filter(dim_Accounts,dim_Accounts[DebitCredit])="Credit") + calculate(Sum(fact_SAP[Amount]),filter(dim_Accounts,dim_Accounts[DebitCredit])<>"Credit")

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@MichelBrown , try like

 

calculate(-1*Sum(fact_SAP[Amount]),filter(dim_Accounts,dim_Accounts[DebitCredit])="Credit") + calculate(Sum(fact_SAP[Amount]),filter(dim_Accounts,dim_Accounts[DebitCredit])<>"Credit")

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hello amitchandak,

Thank you for your quick reply and working solution. I didn't think of this completely other solution and was looking in another direction.

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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