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
Joris_NL
Helper II
Helper II

Measure for counting periods in table 2 which match periods in table 1

Hi all,

 

I'm new to DAX and struggling.

 

I have a LIST OF MONTHS. For each month we have to calculate the NUMBER of rows (clients) that have an ACTIVE and also LONG RELATIONSHIP (>732 days) at the moment of the given month (from the list).

 

TableListOfMonths

GivenMonthStartGivenMonthEndNumberOfClients
1-1-2331-1-23?
1-2-2328-2-23?
1-3-2331-3-23?
1-4-2330-4-23?

 

TableInput

ClientNrStartRelationshipEndRelationshipDurationRelationship
11111111-1-151-1-19

1462

22222221-1-221-1-251097
333333313-2-2115-3-23760

(client numbers are already distinct in this table, no doubles)

 

So, client 11111 isn't active in any of the given months. We don't count this one.

Client 22222 is active in all given months, but at that time, the duration of the relationship is less than 732 days. So it shouldn't count either.

Client 33333 is only active in the first three months, not the fourth. However, it's relationship is only 732 days halfway in the second month, so not long enough for the first month. It should count, but only towards the second and third row.

 

With this limited dataset, column NumberOfClients should result in:

0

1

1

0

 

Do you know how to DAX this? Thanks for the help already!!!

 

Querys are also fine, I can do those.

 

Regards Joris

 

 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Joris_NL ;

You could create a measure as follow:

count = 
CALCULATE(COUNT('Table'[ClientNr]),
FILTER('Table',[StartRelationship]<MAX('Table2'[GivenMonthEnd])
                &&DATEDIFF([StartRelationship],MAX('Table2'[GivenMonthEnd]),DAY)>=732
                &&[EndRelationship]>=MAX('Table2'[GivenMonthStart])))+0

The final show:

vyalanwumsft_0-1669700198347.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Joris_NL
Helper II
Helper II

@v-yalanwu-msft I have an additional question though.

 

Now I need to show an average bandwith of all the counted clients active for >2years. Just to show which months have a very low or very high number of counted clients.

 

I guess I need two new values for that:

BandwithBottom50%OfAverage (i.e. 0,25with the data example of 0-1-1-0)

BandwithTop150%OfAverage (0,75 with the data example)

 

Then with those values, I simply place a new graph on top of the other bar graph, have it visually look the same and will work it out.

 

Unfortunately, simply making a new measure which calculates with our 'Count' measure didn't work for me. It gives an error that a column is expected, not a measure.

 

Any help would be very much appreciated!

Joris_NL
Helper II
Helper II

Wow it works!!!

Thank you!

v-yalanwu-msft
Community Support
Community Support

Hi, @Joris_NL ;

You could create a measure as follow:

count = 
CALCULATE(COUNT('Table'[ClientNr]),
FILTER('Table',[StartRelationship]<MAX('Table2'[GivenMonthEnd])
                &&DATEDIFF([StartRelationship],MAX('Table2'[GivenMonthEnd]),DAY)>=732
                &&[EndRelationship]>=MAX('Table2'[GivenMonthStart])))+0

The final show:

vyalanwumsft_0-1669700198347.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.