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

Matching a date range with a sum of values from a related table(s)

I am looking for a solution to create a report table that originally contains start & end dates and it needs to get a summarized aggregation of costs from two related tables pulled in based on the selected interval in the target table. All the tables are connected by a common key. For a better understanding of the solution required - see a visualization of the target table and relationships of the model attached to post. many thanks in advance for any relevant help!

target_table.jpg

relations.jpg

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @EugeneSledge ,

 

First of all let me share some toughts on the setup you have, because my experience on many-to-many relationships with cross filtering is always difficult to control the final result of the calculations even more when you have more than one table in that situation.

This will cause you model to filter from left to right and right to left and you can have a lot of inconsistent results.

 

In this case you can try to add a measure similar to this one:

 

 

Total Cost1 =
CALCULATE (
    SUM ( Cost1[Amount] ),
    FILTER (
        ALLSELECTED ( Cost1[Date] ),
        Cost1[Date] >= SELECTEDVALUE ( Trips[StartDate] )
            && Cost1[Date] <= SELECTEDVALUE ( Trips[EndDate] )
    )
)

 

 

If thids does not work can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
EugeneSledge
New Member

Many thanks Miguel, your suggested measure worked just fine! thanks again! It was a bit unusual and confusing to see double ampersand "&&" in the syntax but it works just the way I wanted! Thanks again!

Hi @EugeneSledge ,

 

The double ampersand is the equivalent to the AND expression if you do the double vertical pipe "||" it's the equivalent of the OR.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @EugeneSledge ,

 

First of all let me share some toughts on the setup you have, because my experience on many-to-many relationships with cross filtering is always difficult to control the final result of the calculations even more when you have more than one table in that situation.

This will cause you model to filter from left to right and right to left and you can have a lot of inconsistent results.

 

In this case you can try to add a measure similar to this one:

 

 

Total Cost1 =
CALCULATE (
    SUM ( Cost1[Amount] ),
    FILTER (
        ALLSELECTED ( Cost1[Date] ),
        Cost1[Date] >= SELECTEDVALUE ( Trips[StartDate] )
            && Cost1[Date] <= SELECTEDVALUE ( Trips[EndDate] )
    )
)

 

 

If thids does not work can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.