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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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
Anonymous
Not applicable

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

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

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

@Anonymous

 

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

Anonymous
Not applicable

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

@Anonymous

 

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

Anonymous
Not applicable

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

@Anonymous

 

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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors