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
nabarkve
Frequent Visitor

Count of 'Dates Less Than Another Date' from a Separate Table

Hello!

 

I have three tables from three separate data sources. Tables 2 and 3 share a Customer Code value, which I've connected using a de-duped Table 1. I am trying to add a column in Table 3 that would count the number of Doc Date values in Table 2 that are 'less than' the Invoice Date value in Table 3. Please see screenshot below for reference. I'm trying to create the 'Doc Dates Before Invoice Date' column.

 

T&C PowerBI Q.JPG

 

As the relation from Table 2 to 3 is many-to-many, I can't seem to get this linked up to make this calculation happen. Any insight would be much appreciated!

 

Thanks,

Nik

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

@nabarkve ,

 

You can create a calculate column using dax below:

Doc Dates Before Invoice Date = 
VAR Current_Invoice_Date = Table3[Invoice Date]
VAR Current_Customer_Code = Table3[Customer Code]
VAR Row_Number = CALCULATE(COUNT(Table2[Customer Code]), FILTER(Table2, Table2[Customer Code] = Current_Customer_Code && Table2[Doc Date] < Current_Invoice_Date))
RETURN
IF(ISBLANK(Row_Number), 0, Row_Number)

Capture.PNG 

Community Support Team _ Jimmy Tao

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

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

@nabarkve ,

 

You can create a calculate column using dax below:

Doc Dates Before Invoice Date = 
VAR Current_Invoice_Date = Table3[Invoice Date]
VAR Current_Customer_Code = Table3[Customer Code]
VAR Row_Number = CALCULATE(COUNT(Table2[Customer Code]), FILTER(Table2, Table2[Customer Code] = Current_Customer_Code && Table2[Doc Date] < Current_Invoice_Date))
RETURN
IF(ISBLANK(Row_Number), 0, Row_Number)

Capture.PNG 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yuta-msft - Thank you so much! This just saved me so much time! This is exactly what I was looking to achieve.

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.