Forum Discussion

njxfoster's avatar
njxfoster
Icon for Helper I rankHelper I
2 years ago
Solved

Calculate date base on date row and create duplicates

Hi guys     I want to create duplicate row which show duration of a event.   For example, "SetupsStart"=1/26    "AgentsAll In" =1/30   I want to create extra rows which cover the period ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi njxfoster 

     

    I have provided a way to solve your problem:

     

    Here's some dummy data

     

    "Table"

     

    You can create a new date table with the time range "01/26/2024" to "01/30/2024".

     

     

    Date = CALENDAR("1/26/2024", "1/30/2024")

     

     

    Create a measure. Determine the date range and fill in the value.

    Event = 
    var start_date = 
        CALCULATE(
            MAX('Table'[Date]), 
            FILTER(
                ALL('Table'), 
                'Table'[Event] = "SetupsStart"
            )
        )
    var end_date = 
        CALCULATE(
            MIN('Table'[Date]), 
            FILTER(
                ALL('Table'), 
                'Table'[Event] = "AgentsALL In"
            )
        )
    RETURN 
        IF(
            SELECTEDVALUE('Date'[Date]) >= start_date 
            && 
            SELECTEDVALUE('Date'[Date]) <> end_date, 
            "SetupsStart", 
            "AgentsALL In"
        )

     

    Here is the result.

     

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.