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

Calculating Remaining Days from last reporting date

Hi All,

I need some help to solve the following

I have a table with a column maturity date. The maturity date column includes both (i) dates which are before today's date (ii) dates which are after today's date.

 

I want to have a new column which give me the remaining days from a last reporting date (which is not today). The last reporting date to be source from another table such as in below case should be 28-May-21

 

veerub_0-1622886865321.png

 

How should i go about it or if you guys have an easier way to do it?

 

Regards

VB

 

1 ACCEPTED SOLUTION

Hi @veerub , just so we are clear Remaining Days calculates the remaining days from today, and the Date Count calculates from the reporting date to the maturity.  Added some dax to make a negative number if the report date exceeds maturity. Changed the date to 6/3/2021 so that it exceeds the maturity date in one instance.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

DateCount = 
VAR _today =
    TODAY () //This measure returns the count from last reporting date to maturity, but if the bond has already matured, returns the diff from last reporting date to maturity date
VAR _reportDate = [ReportDate]
VAR _bondMaturity =
    MAX ( Maturity[MaturityDate] )
VAR _dateDiff =
    DATEDIFF (
        _reportDate,
        IF ( _today > _bondMaturity, _today, _bondMaturity ),
        DAY
    )

    
var _reverseDateDiff = DATEDIFF(_reportDate,_bondMaturity,DAY)
RETURN
   If(_bondMaturity>_today, _dateDiff,if(_bondMaturity<_reportDate,_reverseDateDiff))

=======================================================================

RemainingDays = 
VAR _today =
    TODAY () //This measure returns 0 if matured else number of remaining dayes
    
    VAR _reportDate = [ReportDate]
VAR _bondMaturity =
    MAX ( Maturity[MaturityDate] )
VAR _dateDiff =
    DATEDIFF (
        _today,_bondMaturity,
         
        DAY
    )

var _reverseDateDiff = DATEDIFF(_reportDate,_bondMaturity,DAY)
RETURN
   If(_bondMaturity>_today, _dateDiff,if(_bondMaturity<_reportDate,_reverseDateDiff))


Capture22788.PNG

 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

8 REPLIES 8
Nathaniel_C
Super User
Super User

Hi @veerub , or if what you are looking at is zero if bond has matured, and the remaing time from today until maturity, try this.

RemainingDays = 
VAR _today =
    TODAY () //This measure returns 0 if matured else number of remaining dayes
    
    VAR _reportDate = [ReportDate]
VAR _bondMaturity =
    MAX ( Maturity[MaturityDate] )
VAR _dateDiff =
    DATEDIFF (
        _today,_bondMaturity,
         
        DAY
    )
RETURN
   If(_bondMaturity>_today, _dateDiff,0)

Capture224.PNG


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Super User
Super User

Hi @veerub , not sure if I understand your final outcome, but try this:

DateCount =
VAR _today =
    TODAY () //This measure returns the count from last reporting date to maturity, but if the bond has already matured, returns the diff from last reporting date to maturity date
VAR _reportDate = [ReportDate]
VAR _bondMaturity =
    MAX ( Maturity[MaturityDate] )
VAR _dateDiff =
    DATEDIFF (
        _reportDate,
        IF ( _today > _bondMaturity, _today, _bondMaturity ),
        DAY
    )
RETURN
    _dateDiff



Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Capture223.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi Nathaniel,

 

Thanks for the response. Here are some additional comments

1. If maturity date < reporting date, it shall return the negative values. that is maturity date minus reporting date.

2. The 57 in your example above is correct. But how did you bring the reportingdate into the model? the reporting date will be a single value. What would be the most appropriate way to get the reportDate updated

 

Regards,

Veeru

Hi @veerub , just so we are clear Remaining Days calculates the remaining days from today, and the Date Count calculates from the reporting date to the maturity.  Added some dax to make a negative number if the report date exceeds maturity. Changed the date to 6/3/2021 so that it exceeds the maturity date in one instance.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

DateCount = 
VAR _today =
    TODAY () //This measure returns the count from last reporting date to maturity, but if the bond has already matured, returns the diff from last reporting date to maturity date
VAR _reportDate = [ReportDate]
VAR _bondMaturity =
    MAX ( Maturity[MaturityDate] )
VAR _dateDiff =
    DATEDIFF (
        _reportDate,
        IF ( _today > _bondMaturity, _today, _bondMaturity ),
        DAY
    )

    
var _reverseDateDiff = DATEDIFF(_reportDate,_bondMaturity,DAY)
RETURN
   If(_bondMaturity>_today, _dateDiff,if(_bondMaturity<_reportDate,_reverseDateDiff))

=======================================================================

RemainingDays = 
VAR _today =
    TODAY () //This measure returns 0 if matured else number of remaining dayes
    
    VAR _reportDate = [ReportDate]
VAR _bondMaturity =
    MAX ( Maturity[MaturityDate] )
VAR _dateDiff =
    DATEDIFF (
        _today,_bondMaturity,
         
        DAY
    )

var _reverseDateDiff = DATEDIFF(_reportDate,_bondMaturity,DAY)
RETURN
   If(_bondMaturity>_today, _dateDiff,if(_bondMaturity<_reportDate,_reverseDateDiff))


Capture22788.PNG

 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi Nathaniel,

Remaining Days calculates the remaining days from reporting date (which represent the DateCount in your example).

The utimate objective is to bucket these remaining days into the following buckets

1. Matured ( all negative values)

2. 0-1 month (0 to 30 days)

3. 3-6 months (31 to 180 days)

4. 6-12 months (181 to 365 days)

5. Above 1 year (greater than 365 days)

 

Can you please share your pbix file. Thanks

Capture2278.PNG
I just built a table with the date in it.  It justs needs to be a separate table.  In your world, where would you get that date?
So in the picture below except for the -numbers, is DateCount, or Remaining Days, the expected outcome.



 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




The reporting date will change on daily basis and will need to be updated by user. What would be the most appropriate way to implement it? Can this be done via an excel?

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.