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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
dwilli10
Regular Visitor

Calculating projected spend between two dates

Hi,

 

I have a table of work orders. Each row has an unique ID, a start date, an end date, and a daily bill rate. With this, I need to calculate the projected spend into the future based on the different start and end dates for each row of data. Note that date data is kept in a separate dimDate table. 

 

Say I have a table called dimDate (note dates are in DD/MM/YYYY format):

DateYearMonthNameMonthNum
1/01/20152015Jan201501
2/01/20152015Jan201501
3/01/20152015Jan201501
4/01/20152015Jan201501
31/12/20252025Dec202512

 

And I have a Workorder table (again, dates are in DD/MM/YYYY format):

WorkOrderIDWorkorder Start DateWorkorder End DateDaily Bill Rate
WO0000041/02/201630/12/201785.75
WO0000012/01/201830/06/201850.25
WO00000514/05/20206/07/2022125.95
WO00000722/02/20223/11/2025160.55
WO00000618/03/202225/08/2024145.25
WO00000215/09/202230/05/202590.85
WO0000081/01/202330/04/202487.9
WO00000325/04/202318/10/2024140.5

 

Neither of the above two tables has any relationship setup. 

 

How might I get the following expected result: 

 

DateWorkOrderIDProjected Spend
1/01/2015blank0
2/01/2015blank0
3/01/2015blank0
1/02/2016WO00000485.75
1/03/2022WO000005125.95
1/03/2022WO000007160.55
19/03/2022WO000005125.95
19/03/2022WO000007160.55
19/03/2022WO000006145.25
30/09/2024WO00000290.85
30/09/2024WO000003140.5

 

The "..." denote a continuation of the date values. The expected result should also be able to calculate projected spend into the future dates from today as can be seen in the lat two rows. 

 

How might I go about implementing this in Power BI? 

 

Thanks in advance. 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@dwilli10,

 

Try this calculated table. It returns a row for each day within the start/end dates for each WorkOrderID. Instead of adding blank fact table rows for every day in your DimDate table (bloats your fact table), you could create a relationship between DimDate and ProjectedSpend. Then, in visuals use DimDate and specify "Show items with no data" if you want to see every row in DimDate.

 

ProjectedSpend = 
VAR vProjectedSpend =
    GENERATE (
        Workorder,
        VAR vStartDate = Workorder[Workorder Start Date]
        VAR vEndDate = Workorder[Workorder End Date]
        VAR vCalendar =
            CALENDAR ( vStartDate, vEndDate )
        RETURN
            vCalendar
    )
VAR vResult =
    SELECTCOLUMNS (
        vProjectedSpend,
        "Date", [Date],
        "WorkOrderID", Workorder[WorkOrderID],
        "Projected Spend", Workorder[Daily Bill Rate]
    )
RETURN
    vResult

 

DataInsights_0-1710864278108.png

 





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

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@dwilli10,

 

Try this calculated table. It returns a row for each day within the start/end dates for each WorkOrderID. Instead of adding blank fact table rows for every day in your DimDate table (bloats your fact table), you could create a relationship between DimDate and ProjectedSpend. Then, in visuals use DimDate and specify "Show items with no data" if you want to see every row in DimDate.

 

ProjectedSpend = 
VAR vProjectedSpend =
    GENERATE (
        Workorder,
        VAR vStartDate = Workorder[Workorder Start Date]
        VAR vEndDate = Workorder[Workorder End Date]
        VAR vCalendar =
            CALENDAR ( vStartDate, vEndDate )
        RETURN
            vCalendar
    )
VAR vResult =
    SELECTCOLUMNS (
        vProjectedSpend,
        "Date", [Date],
        "WorkOrderID", Workorder[WorkOrderID],
        "Projected Spend", Workorder[Daily Bill Rate]
    )
RETURN
    vResult

 

DataInsights_0-1710864278108.png

 





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

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.