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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Mike22
Helper III
Helper III

Create Cycle inside tables to duplicate rows.

Hello Everyone,

 

I am trying to forecast leave for my organization and show the leave balance in the current leave cycle.

I have the following columns

Person IDTotal RemainStaff daily costCurrent Month 
1100406001/06/2018 
5500208001/06/2018 
889106001/06/2018 

 

I have variables which count the current month and the months remaining to the end of the leave cycle.

What I want to obtain is the following, one entry for each month indicating the leave day balance by adding 2.5 days and increasing the month the balance refers to.

 

Person IDTotal remainStaff daily costCurrent Month
1100406001/06/2018
110042.56001/07/2018
1100456001/08/2018
110047.56001/09/2018
1100506001/10/2018
110052.56001/11/2018
1100556001/12/2018
110057.56001/01/2019
1100606001/02/2019
110062.56001/03/2019
5500208001/06/2018
550022.58001/07/2018
5500258001/08/2018
550027.58001/09/2018
5500308001/10/2018
550032.58001/11/2018
5500358001/12/2018
550037.58001/01/2019
5500408001/02/2019
550042.58001/03/2019

 

 

What I tried at the moment is:

 

Absance balanca details = GENERATE(Absence_balance,SELECTCOLUMNS(GENERATESERIES(MONTH(TODAY()),[Months to end cycle]+1),"Remain",Absence_balance[Total remain.]+2.5,"Month",[Month Counter]+1))

 

This is able to duplicate all the rows, the number of times I need. Of course the values [total reamin] and [month counter] are not changing but staying the same, I left the +2.5 and +1 to show you what I am trying to obtain. What can I do to have the system go through the cycle and increase the values I need to be increased?

 

Thanks a lot,

Mike

1 ACCEPTED SOLUTION

Hi @Mike22,

 

>>As you can see it is increasing 2.5 every month but it is giving me the full list of all days of the month. Is it possible to have one value for every month only?

I think it is easy to achieve, you only need to add filter function to choose which day you want to keep.

Expand =
VAR _start =
    FIRSTDATE ( 'Sample'[Current Month] )
VAR _calendar =
    CALENDAR ( _start, DATE ( YEAR ( _start ), 3, 30 ) )
RETURN
    FILTER (
        SELECTCOLUMNS (
            FILTER (
                ADDCOLUMNS (
                    CROSSJOIN ( 'Sample', _calendar ),
                    "Rolling", [Total Remain]
                        + 2.5 * DATEDIFF ( [Current Month], [Date], MONTH )
                ),
                [Rolling]
                    <= [Staff daily cost] + 2.5
            ),
            "Person ID", [Person ID],
            "Rolling", [Rolling],
            "Staff daily cost", [Staff daily cost],
            "Date", [Date]
        ),
        DAY ( [Date] ) = 10
    )

You can also modify 'date' column to year month, then use distinct function to filter duplicate records.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

6 REPLIES 6
v-shex-msft
Community Support
Community Support

HI @Mike22,

 

Please try to use below table formula if it suitable for your requirement.

Expand = 
VAR _start =
    FIRSTDATE ( 'Sample'[Current Month] )
VAR _calendar =
    CALENDAR ( _start, DATE ( YEAR ( _start ), MONTH ( _start ) + 1, 1 ) - 1 )
RETURN
    SELECTCOLUMNS (
        FILTER (
            ADDCOLUMNS (
                CROSSJOIN ( 'Sample', _calendar ),
                "Rolling", [Total Remain]
                    + 2.5 * DATEDIFF ( [Current Month], [Date], DAY )
            ),
            [Rolling]
                <= [Staff daily cost] + 2.5
        ),
        "Person ID", [Person ID],
        "Rolling", [Rolling],
        "Staff daily cost", [Staff daily cost],
        "Date", [Date]
    )

23.gif

 

Notice: I haven't test with sample data who contains multiple months.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft

 

Thank you very much this is great and works perfectly. Just two things please.

 

-I have a variable which indicates the month in which the cycle ends, where do I add this to the formula? So the rows should stop duplicating at the month of march.

 

-There was probably a mis interpretation on the date time format.  I want to add 2.5 on a monthly basis not on a daily basis as it is now.

 

Best regards,

Mike

HI @Mike22,

 

#1. You can modify calendar variable to manually set end date.
#2. You can simply modify datediff function to configure date unit.

 

Expand =
VAR _start =
    FIRSTDATE ( 'Sample'[Current Month] )
VAR _calendar =
    CALENDAR ( _start, DATE ( YEAR ( _start ), 3, 30 ) )
RETURN
    SELECTCOLUMNS (
        FILTER (
            ADDCOLUMNS (
                CROSSJOIN ( 'Sample', _calendar ),
                "Rolling", [Total Remain]
                    + 2.5 * DATEDIFF ( [Current Month], [Date], MONTH )
            ),
            [Rolling]
                <= [Staff daily cost] + 2.5
        ),
        "Person ID", [Person ID],
        "Rolling", [Rolling],
        "Staff daily cost", [Staff daily cost],
        "Date", [Date]
    )

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft

 

It is working thanks, only one small issue left, I guess.

 

Capture.JPG

 

As you can see it is increasing 2.5 every month but it is giving me the full list of all days of the month. Is it possible to have one value for every month only?

 

Capture.2JPG.JPG

 

I have reformatted date to be only year and month so if there is a way to remove duplicates by ID and month it would result in one entry per month.


Let me know if you have any suggestions and thanks a lot for the great help.

Mike

Hi @Mike22,

 

>>As you can see it is increasing 2.5 every month but it is giving me the full list of all days of the month. Is it possible to have one value for every month only?

I think it is easy to achieve, you only need to add filter function to choose which day you want to keep.

Expand =
VAR _start =
    FIRSTDATE ( 'Sample'[Current Month] )
VAR _calendar =
    CALENDAR ( _start, DATE ( YEAR ( _start ), 3, 30 ) )
RETURN
    FILTER (
        SELECTCOLUMNS (
            FILTER (
                ADDCOLUMNS (
                    CROSSJOIN ( 'Sample', _calendar ),
                    "Rolling", [Total Remain]
                        + 2.5 * DATEDIFF ( [Current Month], [Date], MONTH )
                ),
                [Rolling]
                    <= [Staff daily cost] + 2.5
            ),
            "Person ID", [Person ID],
            "Rolling", [Rolling],
            "Staff daily cost", [Staff daily cost],
            "Date", [Date]
        ),
        DAY ( [Date] ) = 10
    )

You can also modify 'date' column to year month, then use distinct function to filter duplicate records.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft

 

This worked perfectly. Thank you so much for your help.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.