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

DAX SSAS : Calculate days measure from another table

Hi Everyone,

I have few date fields in Dimension table, invoice date, due date and Paid date.

Based on the dates I need to calculate the Days Outstanding as a measure in the fact.

any help is really appreciated.

Thanks in advance.

 

invoice noinvoice datedue datePaiddateDays Outstanding 
2001-06-201901-07-201915-08-201945 paid date - due date
2201-07-201901-08-201901-10-201961 paid date - due date
2501-10-201903-10-2019 19today - due date
2802-10-201922-10-201915-10-2019-7 paid date - due date
2802-10-201903-11-2019  due date after today, then 0

 

Here is my dax, but it doesnt seem to work. 

 

SWITCH (
TRUE (),
ISBLANK('Sales Transaction Info'[Date of Paid]) &&
'Sales Transaction Info'[Due Date] < TODAY(), DATEDIFF ( 'Sales Transaction Info'[Due Date], TODAY(), DAY ),
DATEDIFF ( 'Sales Transaction Info'[Date of Paid], 'Sales Transaction Info'[Due Date], DAY ),
0
)

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi medaxing,

The sum of grand total =45 is automatical aggregation of Powerbi, it will refer to measure function(min) to use min value of each field to calculate. In addition, which part of result did you get 0, could you please inform me in details(by screenshots)?

By the way, you also could use calculated column to achieve this goal

Column = if(t2[due date]>TODAY() ,0 ,if(t2[Paiddate]=BLANK(), TODAY()-t2[due date],t2[Paiddate]-t2[due date]))

451.PNG

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
dax
Community Support
Community Support

Hi medaxing,

You could try below measure

Measure =
IF (
    MIN ( t2[due date] ) > TODAY (),
    0,
    IF (
        MIN ( t2[Paiddate] ) = BLANK (),
        TODAY () - MIN ( t2[due date] ),
        MIN ( t2[Paiddate] ) - MIN ( t2[due date] )
    )
)

443.PNG

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

medaxing
Frequent Visitor

Thanks for the quick response.

Somehow, I get zero as the result. also wondering how do get the sum as 45?

dax
Community Support
Community Support

Hi medaxing,

The sum of grand total =45 is automatical aggregation of Powerbi, it will refer to measure function(min) to use min value of each field to calculate. In addition, which part of result did you get 0, could you please inform me in details(by screenshots)?

By the way, you also could use calculated column to achieve this goal

Column = if(t2[due date]>TODAY() ,0 ,if(t2[Paiddate]=BLANK(), TODAY()-t2[due date],t2[Paiddate]-t2[due date]))

451.PNG

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.