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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dw700d
Post Patron
Post Patron

Calculate sum with multiple "AND" conditions

I have two tables seperate tables shown below. An expense table and a revenue table. Both tables have a relationship based on the circuit column. I would like to create a measure that  calculates the total  Revenue  when

Expense does not = 0

and Max Month = December

and  Min Month = January

and Identifier = Y

 

 

Expense Table 

 

CircuitMin  Month       Max Month         Expense            
AJanuaryDecember0
BJanuaryJanuary10
CJanuaryDecember0
DJanuaryDecember20
EAprilJune0
FAprilDecember40
GAprilDecember50
HJanuaryApril10
IJanuaryMay20
JJanuaryDecember30
KJanuaryDecember40
LJanuaryJuly50
MJanuaryDecember40

 

 

Revenue Table
CircuitRevenue           Identifier    
A100Y
B120Y
C200Y
D300Y
E80Y
F100Y
G20Y
H40Y
I60Y
J100Y
K200Y
L20Y
1 ACCEPTED SOLUTION

@dw700d Well, that makes a big difference. Try this:

Measure = 
    VAR __Table = FILTER('Expense', [Expense] <> 0 && 'Expense'[Max Month] = "December" && 'Expense'[Min Month] = "January")
    VAR __Circuits = DISTINCT(SELECTCOLUMNS(__Table, "__Circuits", [Circuit]))
    VAR __Result = SUMX(FILTER('Revenue', [Identifier] = "Y" && [Circuit] IN __Circuits),[Revenue])
RETURN
    __Result

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@dw700d Try:

Measure = 
    VAR __Table = FILTER( 'Revenue', [Identifier] = "Y" && RELATED(Expense[Expense]) <> 0 && RELATED(Expense[Max Month]) = "December" && RELATED(Expense[Min Month]) = "January")
    VAR __Result = SUMX(__Table, [Revenue])
RETURN
    __Result

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  thank you. When I enter the related function intellisense does not give me an option to select a column. The revenue table has unique values and the expense table is the many side of the relationship. Maybe thats why but I am not sure. Any other thoughts?

@dw700d Well, that makes a big difference. Try this:

Measure = 
    VAR __Table = FILTER('Expense', [Expense] <> 0 && 'Expense'[Max Month] = "December" && 'Expense'[Min Month] = "January")
    VAR __Circuits = DISTINCT(SELECTCOLUMNS(__Table, "__Circuits", [Circuit]))
    VAR __Result = SUMX(FILTER('Revenue', [Identifier] = "Y" && [Circuit] IN __Circuits),[Revenue])
RETURN
    __Result

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
saurabhkudale96
Frequent Visitor

Hello @dw700d ,

You can try the below solution. Please upvote if it works for you.

Total Revenue = CALCULATE( SUM(Revenue[Revenue]), Expense[Expense] <> 0, Revenue[Identifier] = "Y", DATESBETWEEN( Revenue[Circuit], FILTER( Expense, Expense[Min Month] = "January" ), FILTER( Expense, Expense[Max Month] = "December" ) ) )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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