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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jbobeck
Frequent Visitor

Counting records based on two dates, second count must exclude records from the first

Hi Folks,

 

I have two tables, a date dimension and a fact.  The fact table has two date columns, the date a record was added and a date if/when it was edited.  What I need to accomplish is generating a count for the number of records added and number of records edited in a date range.  I can accomplish this with two relationships between the two tables and using USERELATIONSHIP() in the count.  The trick is that if a record has both the add and edit date in the range, it should only be included in the add count. This is where it falls apart on me; I can't determine how I can get the edit count to exclude records in the add count.

 

Any advice is welcome, TIA.

1 ACCEPTED SOLUTION

I was able to use this as a basis and got it working:

 

Edited Count =
CALCULATE(
COUNTROWS(FactTable),
USERELATIONSHIP(DateTable[Date], FactTable[EditedDate]),
NOT(FactTable[RecordID] IN VALUES(FactTable[RecordID]))
)

 

I'm not sure how this is giving me the correct answer, but it must recognize the context that the two FactTable[RecordID]s are from different sets.

View solution in original post

5 REPLIES 5
govind_021
Responsive Resident
Responsive Resident

Hey , use this Approach

Edited Count =
CALCULATE(
COUNTROWS(FactTable),
USERELATIONSHIP(DateTable[Date], FactTable[EditedDate]),
NOT(
CONTAINS(
VALUES(FactTable[RecordID]),
FactTable[RecordID],
CALCULATETABLE(
VALUES(FactTable[RecordID]),
USERELATIONSHIP(DateTable[Date], FactTable[AddedDate])
)
)
)
)

I was able to use this as a basis and got it working:

 

Edited Count =
CALCULATE(
COUNTROWS(FactTable),
USERELATIONSHIP(DateTable[Date], FactTable[EditedDate]),
NOT(FactTable[RecordID] IN VALUES(FactTable[RecordID]))
)

 

I'm not sure how this is giving me the correct answer, but it must recognize the context that the two FactTable[RecordID]s are from different sets.

Thanks for the reply!

 

This is giving an error: A function "CONTAINS" has been used in a True/False expressions that is used as a table filter expression.

 

CONTAINS and CALCULATETABLE are new to me, I'll do some exploration with them and see if I can get the error corrected.

lbendlin
Super User
Super User

You can use EXCEPT for that. Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

I'll take a look at how to use EXCEPT.

 

The data is very simple, I have a date dimension with sequential dates from 1950 - 2050.  The fact table is only 4 columns and is laid out like below:

 

FactIDAddDTEditDTRecordValue
11/1/20246/15/2024ABC123
22/16/2024 DEF456
32/22/2024 GHI789
44/19/20246/16/2024JKL012
56/30/20248/1/2024MNO345
67/2/2024 PQR678
78/9/202410/31/2024STU901
810/31/2024 VWX234
911/1/2024 YZZ567
1012/10/2024 AAA890

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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