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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
p-ha
Frequent Visitor

Need help with counting a set of records that meet criteria of 2 dates comparison

Hello PowerBI experienced/super users:

 

I'm very new with PowerBI and am trying to work on a DAX to give me a proper count of records if it falls within the set criteria.

 

Couple facts:

- I'm working on a dataset that is built by IT and calculated columns function is not available. Must use DAX to create measures only.

- All data I have is on same table

- Invoice due date & paid date is [Date] data type

 

Objective: calculate/count all the invoices that incompliance and out of compliance based on the set criterias below (based on the comparison between paid date vs. due date)

 

Table [Invoice] sample data: In this sample, I'd have a count of 2 in compliance and 2 out of compliance.

Invoice idInvoice NumberDue DatePaid DateCompliance  
123A1235/28/2022 in complianceIn Compliancecount distinct invoice id if paid date < due date or (due date > today() and paid date = null)
15648INV-5633/28/20223/27/2022in complianceOut of compliancecount distinct invoice id if paid date > due date or (due date < today () and paid date = null)
78A6567589-IN2/22/20222/15/2022in compliance  
15647INV-1113/28/20224/1/2022out of compliance  
89B8991234/27/2022 out of compliance 

 

 

pha_0-1651183524096.png

Thank you very much for your time!! Any help is greatly appreciated.

P.Ha

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@p-ha . Try measures

 

Calculate(DistinctCOUNT(Table[invoice id]), filter(Table,[paid date] < [due date] || ([due date] > today() && isblank([paid date]))))

 

 

2.

 

Calculate(DistinctCOUNT(Table[invoice id]), filter(Table,[paid date] > [due date] || ([due date] < today() && isblank([paid date]))))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
ddpl
Solution Sage
Solution Sage

Hi,

 

Please try this

 

Status =
IF(
NOT(ISBLANK('Table'[Paid Date]))&&('Table'[Due Date] > 'Table'[Paid Date]),
"Incompliance" ,
IF(
ISBLANK('Table'[Paid Date]) && 'Table'[Due Date] > TODAY(),
"Incompliance","Out of Compliance"
)
)
p-ha
Frequent Visitor

@amitchandak  thank you so much! the guided DAX worked!!

 

1 additional question please if you don't mind, what if my due date falls on the weekend? Is there anything we can add to the current DAX to caviat that if due date falls into weekend, the next earliest paid date is still consider on time? (e.g. due 4/30/2022 [Saturday],  paid 5/2/2022 [earliest next Monday] --> on time payment, rather than the dax to compare just thes sequel of the date itself)

 

OR -

if we can incorporate into  the measure to push the due date to the next business day if it falls in the weekend (since all the Paid date will defaulted to the business days only)

 

Thank you again!

P.Ha

Hi,

 

Step 1 : First you should create weekday column from due date column:

 

weekday = WEEKDAY('Table'[Due Date])
 
Step 2: Create a New column of Due date which replace weekend to next working monday
        
Due Date N = IF('Table'[weekday]=7,'Table'[Due Date] +2,IF('Table'[weekday]=1,'Table'[Due Date]+1,'Table'[Due Date]))
 
 
Step 3 : Final result with 'Incompliance and out of compliance'
 
           
Status =
IF(
NOT(ISBLANK('Table'[Paid Date]))&&('Table'[Due Date N] > 'Table'[Paid Date]),
"Incompliance" ,
IF(
ISBLANK('Table'[Paid Date]) && 'Table'[Due Date N] > TODAY(),
"Incompliance","Out of Compliance"
)
)

 

 

amitchandak
Super User
Super User

@p-ha . Try measures

 

Calculate(DistinctCOUNT(Table[invoice id]), filter(Table,[paid date] < [due date] || ([due date] > today() && isblank([paid date]))))

 

 

2.

 

Calculate(DistinctCOUNT(Table[invoice id]), filter(Table,[paid date] > [due date] || ([due date] < today() && isblank([paid date]))))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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