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
Anonymous
Not applicable

Create a measure that counts values where a condition complies between columns of 2 tables.

Hi all.

 

I have two tables A and B joined by an ID.

On each of the tables, there is a date column.

I'm trying to create a measure that counts the number of rows in which the date of table A is between the date in table B and the date in table B +1 day.

 

Table A

ID    DateA

1      2017-03-02

2      2018-06-03

3      2019-05-13

4      2017-08-23

 

Table B

ID    DateB

1      2017-03-01

2      2018-06-03

3      2014-05-28

4      2015-08-23

 

In this case, Id 1 and 2 have dates that comply with the condition, so the expected value of the measure should be 2.

 

Thanks in advance

1 ACCEPTED SOLUTION

Hi @Anonymous ,
I believe this is what you are looking for in the outcome.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel



Calculated Column

Between =
VAR _curDate = ( TableA[Date] )
VAR _curID = TableA[ID]
VAR _curTableBDate =
    CALCULATE ( MAX ( TableB[Date] ), FILTER ( TableB, TableB[ID] = _curID ) )
VAR _maxPerDate = _curTableBDate + 1
RETURN
    IF ( _curDate >= _curTableBDate && _curDate <= _maxPerDate, "Yes", "No" )

Measure for table in picture.

Between Dates2 =
VAR _curDate =
    MAX ( TableA[Date] )
VAR _curID =
    MAX ( TableA[ID] )
VAR _curTableBDate =
    CALCULATE ( MAX ( TableB[Date] ), FILTER ( TableB, TableB[ID] = _curID ) )
VAR _maxPerDate = _curTableBDate + 1
RETURN
    IF ( _curDate >= _curTableBDate && _curDate <= _maxPerDate, "Yes", "No" )

Measure for Card in picture.

Sum of rows = CALCULATE(COUNTROWS(TableA),TableA[Between]="Yes")




Between dates.PNG

 





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

Proud to be a Super User!




View solution in original post

10 REPLIES 10

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.

Top Solution Authors