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

DAX to calculate difference between two dates in same column with conditions !

Hi All

I need to calculate the difference between the date of receipt of the invoice and the date of payment.

 

Challenge: The two dates are in one column,


- to get the date of receipt of the invoice I need to apply this condition :
BEWTP=E and BWART=101 and WERKS=1000

 

- to get the date of payment I need to apply this condition
BEWTP=Q and SHKZG=S and WERKS=1000 

 

Shak_95_0-1659557369390.png

 

Shak_95_1-1659557409350.png

Shak_95_3-1659557453658.png

Shak_95_4-1659557707189.png

 

Your answer is appreciated

 

1 ACCEPTED SOLUTION
changqing
Resolver II
Resolver II

Hi @Shak_95 ,

 

Suppose there is a table like this(There should be an invoice id column):

changqing_1-1660039833690.png

Then new a calculated column:

days = 
VAR _mindate =
    CALCULATE (
        MIN ( 'Table'[CPUDT_DATE] ),
        FILTER (
            'Table',
            'Table'[BEWTP] = "E"
                && 'Table'[BWART] = 101
                && 'Table'[WERKS] = 1000
                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
        )
    )
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[CPUDT_DATE] ),
        FILTER (
            'Table',
            'Table'[BEWTP] = "Q"
                && 'Table'[SHKZG] = "S"
                && 'Table'[WERKS] = 1000
                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
        )
    )
VAR _difference =
    DATEDIFF ( _mindate, _maxdate, DAY )
RETURN
    _difference

changqing_2-1660039948074.png

The PBIX file is attached for reference.

PBIX file 

 

Best Regards,
changqing

View solution in original post

6 REPLIES 6
changqing
Resolver II
Resolver II

Hi @Shak_95 ,

 

Suppose there is a table like this(There should be an invoice id column):

changqing_1-1660039833690.png

Then new a calculated column:

days = 
VAR _mindate =
    CALCULATE (
        MIN ( 'Table'[CPUDT_DATE] ),
        FILTER (
            'Table',
            'Table'[BEWTP] = "E"
                && 'Table'[BWART] = 101
                && 'Table'[WERKS] = 1000
                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
        )
    )
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[CPUDT_DATE] ),
        FILTER (
            'Table',
            'Table'[BEWTP] = "Q"
                && 'Table'[SHKZG] = "S"
                && 'Table'[WERKS] = 1000
                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
        )
    )
VAR _difference =
    DATEDIFF ( _mindate, _maxdate, DAY )
RETURN
    _difference

changqing_2-1660039948074.png

The PBIX file is attached for reference.

PBIX file 

 

Best Regards,
changqing

Thank you very much changqing for your help, i appreciate it

Shak_95
Frequent Visitor

UP

Shak_95
Frequent Visitor

kindly help

technolog
Super User
Super User

I think that you can try to use SUMMARIZE and after that use ADDCOLUMNS with MAX(Date) - MIN(Date)

thank you for your reply

 

Kindly, can you share the expression and steps that achieves what i want.

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.