Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
10 years ago
Solved

Holiday Calculation: From Start and End Date to "Aggregation Graph"

Hello everyone, Hello Dax-Experts, :robothappy:   I'm new to Power BI, and I have only a limited Knowledge of DAX.   The following Problem keeps driving me nuts the whole last week:   I have an...
  • Sean's avatar
    10 years ago

    Hi Anonymous !

     

    It seems we can achieve this by just slightly modifying OwenAuger's solution here :smileyhappy:

    http://community.powerbi.com/t5/Desktop/Generate-a-schedule-table/m-p/38834#M14436

     

    Holiday Schedule =
    SUMMARIZE (
        GENERATE (
            HolidayTable,
            CALCULATETABLE (
                VALUES ( 'Calendar'[Date] ),
                DATESBETWEEN (
                    'Calendar'[Date],
                    HolidayTable[Start Date],
                    HolidayTable[End Date]
                )
            )
        ),
        HolidayTable[Name],
        'Calendar'[Date],
        HolidayTable[Qualification]
    )

     

    Here's the result...

     

    and the slicers you mentioned you'd like to use seem to work as well

     

    Hope this helps and works in your case! :smileyhappy:

     

    EDIT: The Qualification Slicer was not included in the previous pictures :smileyhappy: 

  • Anonymous's avatar
    Anonymous
    10 years ago

    Alternatively, here's my previous method. This was done without creating a new transformed table. Just a measure. Well, a measure and a date table...

     

    I had a table where each record had a PersonID, a start date, and an end date. I had a date table with no active relationship to the other table. Having no relationship is important. Then I created a measure to count based on start and end dates. Put on a visual with some aggregation of a period dates (i.e. week, month, etc), this would give a count of active records during that time period.

     

    Active Count = CALCULATE(

    DISTINCTCOUNT(Table[PersonID]),

    FILTER(

    Table,

    Table[Start Date] <= LASTDATE(DateTable[Date]) &&

    Table[EndDate] >= FIRSTDATE(DateTable[Date])

    )

    )

     

    The FIRSTDATE/LASTDATE thing always feels a little counterintuitive to me. The start and end look backward, but think of it this way: if they started anytime before the end of the period, then they were active during the period. Also if they ended anytime after the beginning of the period (whether that's during the period or after the end of the period), they were still active during the period. Make sense?

     

    Also, Anonymous Dax-Experts: Daxperts?