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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
benthomas
Regular Visitor

Help with calculations based on similar dates and other conditions

Hi there,

 

I have data in the following format:

data.jpg

 

I find this hard to explain but one of the ways in which I need to display this data is in a simple bar graph showing the total number of nights per team.  The trouble I'm having is when there are multiple entries for the same team in an encompassing date range.  The reason for the additional entry/s is that one staff member only did two nights instead of three so an individual entry is created for them in order to still record the nights per person metric.

 

As per the above highlighted example, the 'Team' has spent in total 3 nights away but at the moment it's summing it as 5.  How am I able to calculate/display this number correctly whereby it looks at the total nights away for the 'Team' being 3 rather than summing it as 5.

 

The dates are the key here, if there are multiple entries for the same team during a date range that encompasses another for the same team, it can be assume that it should be concurrent rather than cumulative as far as the count goes.

 

I hope that makes sense.  The way we're recording this now allows for the night per person to be calculated and displayed no problems, but the nights per team is my challenge.

 

Cheers.

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture2.png

 

Total nights per team: = 
SUMX (
    ADDCOLUMNS (
        GROUPBY (
            Data,
            Data[Team],
            Data[Departure Date],
            "@maxreturndate", MAXX ( CURRENTGROUP (), Data[Return Date] )
        ),
        "@nights", INT ( [@maxreturndate] - Data[Departure Date] )
    ),
    [@nights]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture2.png

 

Total nights per team: = 
SUMX (
    ADDCOLUMNS (
        GROUPBY (
            Data,
            Data[Team],
            Data[Departure Date],
            "@maxreturndate", MAXX ( CURRENTGROUP (), Data[Return Date] )
        ),
        "@nights", INT ( [@maxreturndate] - Data[Departure Date] )
    ),
    [@nights]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you so much for that - I'm trying to teach myself this so it's hard to know which direction to go to get the results I'm after.  I am looking at the file you provided, am I correct in deploying this as a 'quick measure', or is there another better method to 'deploy' it?

I also understand some of your expression but not the whole thing, will it consider those circumstances where the departure and/or return date is different but still encompassed by a greater date range.

 

Eg.

DepRetTeamStaff
10/01/202220/01/2022Team 125
12/01/202218/01/2022Team 122

 

Thank you so much.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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