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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Jodallen123
Helper I
Helper I

Count distinct ordernumbers where datediff < 0

Hello everyone,

 

I have recently started working with a table consisting of date logs, which I find very tricky. I made a similar thread yesterday and got really good help so I had hoped to get some help today aswell. 

 

My data looks something like this. I am trying to count the distinct ordernumbers where the difference between min "Status created date" for status A and min "Status created date" för status B is negative. 

Jodallen123_0-1695794527430.png

This is my current measure: 

 

PL # Revision distinct 5 =

AVERAGEX(
    VALUES(logs'[Ordernumber] ),
    Var kundfbso = CALCULATE (
        MIN ( logs'[Created_date] ),
        FILTER (
            'logs',
            'logs'[status_changed_to] = "A"
                ||'logs'[status_changed_to] = "B"
        ))

    Var kundfb =  CALCULATE (
        MIN ( logs'[Created_date] ),
        'logs'[status_changed_to] = "C"
    )
    Var diff =  DATEDIFF( kundfbso, kundfb, DAY )

    return
    diff
)
 
When I drag this measure to a table with ordernumber, it gives the correct number of days per order, but I don't know how to count the distinct ordernumbers where the datediff < 0. 
 
If anyone has any ideas how I can move forward from here I would really appreciate it.
 
Thanks in advance! 
2 REPLIES 2
Jodallen123
Helper I
Helper I

Creating a second measure that looks like this works: 

 

# PL Revision correct =
COUNTX (
    FILTER (
        VALUES ( logs'[Ordernumber] ),
        [PL # Revision distinct 5] < 0
    ),
     logs'[Ordernumber]
)
 
How can I incorporate this into the first measure and get the same output?
 
Thanks!
 
Jodallen123
Helper I
Helper I

I still haven't figured this out so if anybody has any ideas I'm all ears. 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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