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

Count in two related tables

Hi,

 

I cannot figure out this problem (I am novice to PowerBI).

I have two tables. First table contains dates, I would like to count number of rows from another table that has dates older than the current row. I would like to do it for each row (passing current date for given row in the first table). It seems to be simple - but I am not getting right results. Here is the query I use:

 

test1 = CALCULATE(COUNTROWS(ReportCurrentSprint), FILTER(ReportCurrentSprint, FullSprint[Date] >= ReportCurrentSprint[Completed Date]))

S1.png

For 1/25/2019 - I should see 4 (as in column Count of All Previus - but here I hardcoded the date), however the results in column test1 are totally different - I am not even sure what I am getting.

1 ACCEPTED SOLUTION
Farquaad
Frequent Visitor

I found solution - most probably there is more elegant way of doing this, please let me know if you come up with something better.

 

The problem is that one table contains datetime with time part always starting at 12 am. The other table has also datetime, and while the date part is corresponding to the first table, the time part could be anything between 12 am and 11:59 pm. So to solve this, I created new columns in each table, dropping the time parts, leaving only short dates. This allowed me to create relationship between the tables and the COUNTROWS started working.

 

View solution in original post

3 REPLIES 3
Farquaad
Frequent Visitor

I found solution - most probably there is more elegant way of doing this, please let me know if you come up with something better.

 

The problem is that one table contains datetime with time part always starting at 12 am. The other table has also datetime, and while the date part is corresponding to the first table, the time part could be anything between 12 am and 11:59 pm. So to solve this, I created new columns in each table, dropping the time parts, leaving only short dates. This allowed me to create relationship between the tables and the COUNTROWS started working.

 

Greg_Deckler
Super User
Super User

Are the 2 tables related to one another? I take it that the table shown is the FullSprintDate table? What if [Completed Date] in the other table is blank?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

 

the tables are not related unfortunately, so I cannot use RELATED or RELATEDTABLE. The table shown is FullSprint. I will want to ignore rows with blanks, but at this point I cannot even get it working with populated data.

 

Thank you for looking into this

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.