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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Mus123
Frequent Visitor

DAX: Loop

Hi all, I am trying to create a DAX loop that will help me solve the following:

 

Background:

 

  1. I have a column for actuals
  2. column for YearMonth (e.g 20209, 202010,202011,...............202209) 25 months
  3. column for PaymentMonth
  4. PaymentMonth has numbers 1 to 25 for each month
  5. Each YearMonth has PaymentMonth #1 to 25

Pain point:

  • Dax loop that will perform the following,
  • The 20209 period -sum all actuals if the PaymentMonth <=25, 202010 period-sum all actuals if the PaymentMonth <=24,

 202011 period-sum all actuals if the PaymentMonth <=23...............................................20229 period-sum all actuals if the       PaymentMonth <=1,

3 REPLIES 3
Mus123
Frequent Visitor

@Anonymous 

Anonymous
Not applicable

Hi  @Mus123 ,

I created some data:

vyangliumsft_0-1670895549294.png

 

Here are the steps you can follow:

1. Create calculated column.

Flag =
var _dis=DISTINCTCOUNT('Table'[YearMonth])
return
_dis - [PaymentMonth] +1
Loop =
var _1=SELECTCOLUMNS(FILTER(ALL('Table'),[YearMonth]=EARLIER('Table'[YearMonth])),"1",[PaymentMonth])
return
SUMX(FILTER(ALL('Table'),
'Table'[Flag] in _1 ),[Value])

2. Result:

vyangliumsft_1-1670895549295.png

 

Best Regards,

Liu Yang

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

@Anonymous  my data looks like this:

Each year_month has payment_month that runs from 1 to 25.

Mus123_1-1670915349044.png

 

Thank you.

 

P/S once the condition is met, I want to sum the actuals. e.g 20209 -sum all actuals if the payment month is <=25,

202010 -sum all actuals  if the payment month is <=24 ......etc

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.