Forum Discussion

fleming507's avatar
fleming507
Frequent Visitor
8 years ago
Solved

Number of Days Value to Rows

 I have a dataset that I need to maniuplate for year end reporting, but the data from source is not entirely suitable. For each service there is a Scheduled Start Date and Numbder of days scheduled. What I'm trying to do is join it on to a calendar table (or something else) so that I have a row for each day scheduled (excluding weekends)

 

eg,

 

ServiceName    ScheduledStartDate   NumberOfDays

InstallApp         19/07/2018                5.0

 

to become...

 

ServiceName   ScheduledDate

InstallApp        19/07/18

InstallApp        20/07/18

InstallApp        23/07/18

InstallApp        24/07/18

InstallApp        25/07/18

 

I have a good idea how I would do this in SQL, but im trying to avoid using a database layer in between

 

Thanks

  • Hi fleming507

     

    Try this calculated table. Assuming your table name is Table1

     

    Table =
    VAR Temp1 =
        GENERATE (
            Table1,
            VAR mydays =
                CALCULATE (
                    VALUES ( Table1[ NumberOfDays] ),
                    Table1[ServiceName] = EARLIER ( Table1[ServiceName] )
                )
            VAR adddays =
                (
                    INT ( mydays / 7 )
                        + 1
                )
                    * 2
            RETURN
                GENERATESERIES ( 1, mydays + adddays )
        )
    VAR temp2 =
        ADDCOLUMNS (
            ADDCOLUMNS ( Temp1, "Scheduled Dates", [ScheduledStartDate ] + [Value] - 1 ),
            "WeekDay", WEEKDAY ( [Scheduled Dates], 2 )
        )
    VAR temp3 =
        FILTER ( temp2, [WeekDay] < 6 )
    VAR temp4 =
        ADDCOLUMNS (
            temp3,
            "RANK", RANKX (
                FILTER ( temp3, [ServiceName] = EARLIER ( [ServiceName] ) ),
                [Scheduled Dates],
                ,
                ASC,
                DENSE
            )
        )
    VAR temp5 =
        FILTER ( temp4, [RANK] <= [ NumberOfDays] )
    RETURN
        SUMMARIZE ( temp5, [ServiceName], [Scheduled Dates] )

7 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    Hi fleming507

     

    Try this calculated table. Assuming your table name is Table1

     

    Table =
    VAR Temp1 =
        GENERATE (
            Table1,
            VAR mydays =
                CALCULATE (
                    VALUES ( Table1[ NumberOfDays] ),
                    Table1[ServiceName] = EARLIER ( Table1[ServiceName] )
                )
            VAR adddays =
                (
                    INT ( mydays / 7 )
                        + 1
                )
                    * 2
            RETURN
                GENERATESERIES ( 1, mydays + adddays )
        )
    VAR temp2 =
        ADDCOLUMNS (
            ADDCOLUMNS ( Temp1, "Scheduled Dates", [ScheduledStartDate ] + [Value] - 1 ),
            "WeekDay", WEEKDAY ( [Scheduled Dates], 2 )
        )
    VAR temp3 =
        FILTER ( temp2, [WeekDay] < 6 )
    VAR temp4 =
        ADDCOLUMNS (
            temp3,
            "RANK", RANKX (
                FILTER ( temp3, [ServiceName] = EARLIER ( [ServiceName] ) ),
                [Scheduled Dates],
                ,
                ASC,
                DENSE
            )
        )
    VAR temp5 =
        FILTER ( temp4, [RANK] <= [ NumberOfDays] )
    RETURN
        SUMMARIZE ( temp5, [ServiceName], [Scheduled Dates] )
  • v-piga-msft's avatar
    v-piga-msft
    Resident Rockstar

    Hi fleming507,

     

    The answer of Zubair_Muhammad should solve your problem.

     

    If you have solved your problem, please accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

     

    Best Regards,

    Cherrry

  • fleming507's avatar
    fleming507
    Frequent Visitor

    I thought I replied to this, seems to have disappeared.

     

    This solution works in most cases but where service may be 0.5 or 1 even 2 days it seems to add an extra day on the end.

      • fleming507's avatar
        fleming507
        Frequent Visitor

        Thanks zubair, on further review my data was erronous. once corrected I achieved the desired reults with the original solution.