Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Help needed: Sum values based on date checking, two related tables.

I have two tables, joined on location. I need to determine what the daily budget hours from the LocationBudget table based on the location and date in the LocationCalendar table.

 

What I'm trying to accomplish:

IF LC.Date greater than equal LB.BudgetStart

AND LC.Date less than equal LB.BudgetEnd

THEN SUM(LB.BudgetHours ) as LC.DailyHours

 

Table: LocationCalendar (LC)

LocationDateDailyHours
House17/1/208
House17/15/208
House18/15/204
House27/1/2016
House27/15/2016
House28/15/2010

 

Table: LocationBudget (LB)

LocationBudgetStartBudgetEndBudgetHours
House17/1/207/31/208
House18/1/208/31/204
House27/1/207/31/2016
House28/1/208/31/2010

 

Any help would be greatly appreciated. Thanks so much!

  • Here is a column expression that should get your desired result.

     

    Daily Hours =
    VAR thisdate = LocationCalendar[Date]
    RETURN
        CALCULATE (
            MIN ( LocationBudget[BudgetHours] ),
            LocationBudget[BudgetStart] <= thisdate,
            LocationBudget[BudgetEnd] >= thisdate
        )

     

    Regards,

    Pat

     

     

     

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    Here is a column expression that should get your desired result.

     

    Daily Hours =
    VAR thisdate = LocationCalendar[Date]
    RETURN
        CALCULATE (
            MIN ( LocationBudget[BudgetHours] ),
            LocationBudget[BudgetStart] <= thisdate,
            LocationBudget[BudgetEnd] >= thisdate
        )

     

    Regards,

    Pat

     

     

     

  • Anonymous Sorry i am kind of finding it difficult to understand , Can you show me how should your output table look like so that i can try the logic if possible