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
FelixB
New Member

DAX - kind of Calculate(SUM ... condition 1 and use input from another) or SUMX of 2 tables

Hi all,

I have 2 tables with the fields

  • Kilometers
    • Vehicle
    • Date
    • Km on the date
  • Activities
    • Vehicle
    • ActivityID
    • FinishDate

 

The tables are connected via a vehicle table. I cannot connect the date table with the activities table.

 

I would like to sum the kilometers when the Kilometers(Date) > Activities(Finish Date) for Activity = 2.

 

Can you help me, please? What other information do you need?

 

5 REPLIES 5
foodd
Super User
Super User

How to Get Your Question Answered Quickly  meaning, please add your work-in-progress Power BI Desktop file, and source data in Excel format.

punitkhatri
Helper III
Helper III

Hii, @FelixB according to the information you have provided this formula should work if all the relationships are proper.
Formula =
CALCULATE(SUM('Kilometers'[Km on the date]),
'Kilometers'(Date) > 'Activities'(Finish Date)  && 'Activities'(ActivityID) = "2")

Please let me know if this works or not, if it doesn't work please provide a sample data to work on which will make it easy for me to help.

The error message: The expression contains columns from multiple tables but only columns from a signle table can be used in a True/False expression that is used as a table filter expression.

Please provide a sample data. So that I can see what exactly is the problem.

I was not able to upldate example data but the solution is:

 

Output =

VAR A = CALCULATE(MAX(Activities[FinishDate]), FILTER(Activities, Activities[ActivityID] = 2))

RETURN CALCULATE(SUM(Kilometers[Kilometer]), FILTER(Kilometers, Kilometers[Date] > A))

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.