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

Divide and sum based on selected future dates

I would like to recreate an excel formula in dax as follows:

 

=IF(AND(Selected Value > Start Date , Selected Value < End Date)=TRUE,(Cost/Lifetime in Months),0)

 

I have a listing of assets which each have a start and end date of their useful life. I also have a calendar table containing future dates which I would like my slicer to be built on. When selecting a future month, quarter or fiscal year, I would like a measure that calculates the total amount for the selected period. So if an item's end date is June 30th 2023, I want to see the total incurred for fiscal year 2023 which would be the cost divided by lifetime in months * 6 and so forth for each item. 

 

Can someone help me with a solution? 

1 ACCEPTED SOLUTION

Hi @jayped ,

For this, Id use both DAX and Power Query.  Power Query to create a rows of start and end dates of the months included in the lifetime of the product and DAX to get the depreciation amount. Once the calculated rows fom PQ have been loaded, I can then use this measure to calculate for the depreciation.

Depreciation = 
VAR MinDate =
    MIN ( 'Calendar'[Start] )
VAR MaxDate =
    MAX ( 'Calendar'[End] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Monthly (Cost/Lifetime)] ),
        FILTER (
            'Table',
            'Table'[Start of Month] >= MinDate
                && 'Table'[End of Month] <= MaxDate
        )
    )

 

 

Here is a result screenshot of this approach.

danextian_0-1664340809997.png

Here's a sample pbix for your reference: https://drive.google.com/file/d/1YC_b0Ws0fi42p-VW0JUMl7jloMjd_Lg8/view?usp=sharing 

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

5 REPLIES 5
danextian
Super User
Super User

Hi @jayped ,

 

Can you please post a sample data and your expected result. It is hard to imagine what you are trying to achieve without seeing those information.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/td-p/1447523/jump...










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

For simplicity, I'd have a table set up like below.

 

ItemStart DateEnd DateLifetime in MonthsCostMonthly (Cost/Lifetime)
Printer1-Nov-1931-Oct-2236         6,000.00                166.67
Shredder1-Jul-1830-Jun-2136         4,500.00                125.00
Television1-Feb-2231-Jan-2536         4,000.00                111.11
Desk1-Jun-2131-May-2660         3,500.00                   58.33
Laptops1-Aug-2231-Jul-2536         3,000.00                   83.33

 

And I also have a calendar table containing dates up to 2027 and I'll create a couple slicers like below:

 

jayped_0-1664313895238.png

 

Upon selecting FY25 and Q3 (Jul-Sep 2025), how can I create a measure that calculates a total of 258.32 ((58.33 * 3) + 83.33) because for the desk, FY25 Q3 falls between the start and end date and for the laptops only one month can be accounted for because the end date is Jul 31.

 

Hope this helps.

 

 

Hi @jayped ,

For this, Id use both DAX and Power Query.  Power Query to create a rows of start and end dates of the months included in the lifetime of the product and DAX to get the depreciation amount. Once the calculated rows fom PQ have been loaded, I can then use this measure to calculate for the depreciation.

Depreciation = 
VAR MinDate =
    MIN ( 'Calendar'[Start] )
VAR MaxDate =
    MAX ( 'Calendar'[End] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Monthly (Cost/Lifetime)] ),
        FILTER (
            'Table',
            'Table'[Start of Month] >= MinDate
                && 'Table'[End of Month] <= MaxDate
        )
    )

 

 

Here is a result screenshot of this approach.

danextian_0-1664340809997.png

Here's a sample pbix for your reference: https://drive.google.com/file/d/1YC_b0Ws0fi42p-VW0JUMl7jloMjd_Lg8/view?usp=sharing 

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

This is good. Thanks a mil!

danextian
Super User
Super User

Hi @jayped ,

 

Can you please post a sample data and your expected result. It is hard to imagine what you are trying to achieve without seeing those information.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/td-p/1447523/jump-to/first-unread-message










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

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.