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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Brite
Helper I
Helper I

How to create a loop for once every month on the 1st to add a new query

Hello,

I am having to edit this DAX formula every month on the 1st. Is there a way to create a loop so that on the first of every month it plugs in current data and adds one month for every loop: Month_12 = if(Month(Today()="[CURRENT MONTH]" && Year(TODAY()="[CURRENT YEAR]", calculate(Divide([Month 12],[Month 1]), 'Calendar BV' [MonthYear] = "May-22", 'Calendar BV' [MonthYear] ="June-22"...         --> +1 month for every loop that is made once a month

 

Any help is greatly appreciated!!

 

Month 2_% = if(MONTH(TODAY())=4 && YEAR(TODAY())=2022, calculate(Divide([Month 2 N],[Month 1]), 'Calendar BV'[MonthYear] = "May-21" ||  'Calendar BV'[MonthYear] = "Jun-21" ||  'Calendar BV'[MonthYear] = "Jul-21"  || 'Calendar BV'[MonthYear] = "Aug-21" ||  'Calendar BV'[MonthYear] = "Sep-21" ||  'Calendar BV'[MonthYear] = "Nov-21" || 'Calendar BV'[MonthYear] = "Dec-21" ||  'Calendar BV'[MonthYear] = "Jan-22"  ||  'Calendar BV'[MonthYear] = "Feb-22"), 
if(MONTH(TODAY())=5 && YEAR(TODAY())=2022, calculate(Divide([Month 2 N],[Month 1]), 'Calendar BV'[MonthYear] = "May-21" ||  'Calendar BV'[MonthYear] = "Jun-21" ||  'Calendar BV'[MonthYear] = "Jul-21"  || 'Calendar BV'[MonthYear] = "Aug-21" ||  'Calendar BV'[MonthYear] = "Sep-21" ||  'Calendar BV'[MonthYear] = "Nov-21" || 'Calendar BV'[MonthYear] = "Dec-21" ||  'Calendar BV'[MonthYear] = "Jan-22"  ||  'Calendar BV'[MonthYear] = "Feb-22" || 'Calendar BV'[MonthYear] ="Mar-22"), 
if(MONTH(TODAY())=6 && YEAR(TODAY())=2022,  calculate(Divide([Month 2 N],[Month 1]), 'Calendar BV'[MonthYear] = "May-21" ||  'Calendar BV'[MonthYear] = "Jun-21" ||  'Calendar BV'[MonthYear] = "Jul-21"  || 'Calendar BV'[MonthYear] = "Aug-21" ||  'Calendar BV'[MonthYear] = "Sep-21" ||  'Calendar BV'[MonthYear] = "Nov-21" || 'Calendar BV'[MonthYear] = "Dec-21" ||  'Calendar BV'[MonthYear] = "Jan-22"  ||  'Calendar BV'[MonthYear] = "Feb-22" || 'Calendar BV'[MonthYear] ="Mar-22" || 'Calendar BV'[MonthYear] ="Apr-22"), 
if(MONTH(TODAY())=7 && YEAR(TODAY())=2022,  calculate(Divide([Month 2 N],[Month 1]), 'Calendar BV'[MonthYear] = "May-21" ||  'Calendar BV'[MonthYear] = "Jun-21" ||  'Calendar BV'[MonthYear] = "Jul-21"  || 'Calendar BV'[MonthYear] = "Aug-21" ||  'Calendar BV'[MonthYear] = "Sep-21" ||  'Calendar BV'[MonthYear] = "Nov-21" || 'Calendar BV'[MonthYear] = "Dec-21" ||  'Calendar BV'[MonthYear] = "Jan-22"  ||  'Calendar BV'[MonthYear] = "Feb-22" || 'Calendar BV'[MonthYear] ="Mar-22" || 'Calendar BV'[MonthYear] ="Apr-22" || 'Calendar BV'[MonthYear] = "May-22"), Blank()))))  

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Brite ,

 

Are you deliberately missing Oct-21?

If so, you could try creating below measure if there's a date field in your 'Calendar BV'.

Month 2_% =
VAR _START =
    DATE ( 2021, 5, 1 )
VAR _NUMBER =
    MONTH ( TODAY () ) - 4
VAR _END =
    EOMONTH ( _start, 9 + _NUMBER )
RETURN
    CALCULATE (
        DIVIDE ( [Month 2 N], [Month 1] ),
        FILTER (
            'Calendar BV',
            [Date] >= _START
                && [Date] <= _END
                && MONTH ( [Date] ) <> 10
                && YEAR ( [Date] ) <> 2021
        )
    )

If you accidentally miss October, delete the October 21 filter statement.

   

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

View solution in original post

2 REPLIES 2
Brite
Helper I
Helper I

@AnonymousThank you! This works great

Anonymous
Not applicable

Hi @Brite ,

 

Are you deliberately missing Oct-21?

If so, you could try creating below measure if there's a date field in your 'Calendar BV'.

Month 2_% =
VAR _START =
    DATE ( 2021, 5, 1 )
VAR _NUMBER =
    MONTH ( TODAY () ) - 4
VAR _END =
    EOMONTH ( _start, 9 + _NUMBER )
RETURN
    CALCULATE (
        DIVIDE ( [Month 2 N], [Month 1] ),
        FILTER (
            'Calendar BV',
            [Date] >= _START
                && [Date] <= _END
                && MONTH ( [Date] ) <> 10
                && YEAR ( [Date] ) <> 2021
        )
    )

If you accidentally miss October, delete the October 21 filter statement.

   

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.