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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
bbass82
Helper I
Helper I

Need Support - Trying to build recursive M code or DAX for POS sales projections in future weeks

Good Morning,

 

Really need some support here as I am at a loss for where to go next. Been a user for little under a year now and was presented with a task by my business to come up with POS sales ladders that could show future week POS sales projections based on trendlines provided by our demand planners. Essentially what I am trying to build is a visual table that is by Week / Actual POS Sales (up to current calendar week) / Projected POS Sales (anything greater than current week-1). 

 

Below is an example of the logic I want to build for calendars weeks 1 to 52. I will have slicers also in the dashboard based on customer and material. 

 

want a calculated column for Projected POS Unitsthat:

  • Uses actual POS if available.
  • Otherwise uses the previous week's projected POS.
  • Works recursively from week 1 to 52.
  • Respects customer + material context.
  • Confirming this is the logic I am looking to build 🧠 Example Logic (Just to Confirm)
    Let’s say you have:

    Week     Actual POS Units   Trendline
    WEEK 1           100                  1.05
    2                                             1.10
    3                                             1.08
    Then the projection would be:

    Week 2 = 100 × 1.10 = 110
    Week 3 = 110 × 1.08 = 118.8
    This is the behavior I want it to follow. 

I have attached test data based on the real subset to show what criteria I have in the merged table for POS sales and trendlines. I have also attached a copy of the M Code I was hoping would work but it is only giving a return of logic and not values (why I don't know)

 

Any help with this matter would be greatly appreciated. 

 

Customer NameProduct FamilyMaterialMaterial DescriptionPlanning YearCalendar MonthWeek NumberPOS $POS UnitsTrendline Value
Walmart712126017496Elmo Playset2025JAN1 $ 1,389.602481.012237
Walmart712126017496Elmo Playset2025JAN2 $ 2,414.034311.0001474
Walmart712126017496Elmo Playset2025JAN3 $ 2,448.604440.93949
Walmart712126017496Elmo Playset2025JAN4 $ 2,556.305161.2354279
Walmart712126017496Elmo Playset2025JAN5  0.93949
Walmart712126017496Elmo Playset2025FEB6  1.012237
Walmart712126017496Elmo Playset2025FEB7  1.0001474
Walmart712126017496Elmo Playset2025FEB8  1.2354279
Walmart712126017496Elmo Playset2025FEB9  0.93949
Costco712126017496Elmo Playset2025JAN1 $ 1,192.672011.0001474
Costco712126017496Elmo Playset2025JAN2 $ 2,313.704041.012237
Costco712126017496Elmo Playset2025JAN3 $ 2,906.615020.93949
Costco712126017496Elmo Playset2025JAN4 $ 3,426.206091.2354279
Costco712126017496Elmo Playset2025JAN5  0.93949
Costco712126017496Elmo Playset2025FEB6  1.012237
Costco712126017496Elmo Playset2025FEB7  1.024432
Costco712126017496Elmo Playset2025FEB8  1.101096
Costco712126017496Elmo Playset2025FEB9  0.94949

 

 

M-Code Statement.PNG

8 REPLIES 8
v-karpurapud
Community Support
Community Support

Hi @bbass82 

Thank you for submitting your question to the Microsoft Fabric Community Forum, and thanks to @AlexisOlson and @Greg_Deckler  for offering helpful suggestions.

 

Could you let us know if the suggested solution resolved your issue?If you still need help, please share more details so we can assist you further.

 

Thank you.

Greg_Deckler
Community Champion
Community Champion

@bbass82 Why not just duplicate your POS $ column and then do a Fill Down? Just make sure it is sorted correctly?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

 

Thank-you for the quick response. Sorry could you give me more detail on this possible solution? Right now our planners are updating the trednlines weekly based on new actualized POS in previous week / marketing spend changes etc. 

 

I am hoping to create a table visual that essentially just shows week # / actual POS sales/ Projectioned POS Sales / Cumulative (Actuals + Projected)

 

Week     Actual POS Units   Trendline
WEEK 1           100                  1.05
2                                             1.10
3                                             1.08
Then the projection would be:

Week 2 = 100 × 1.10 = 110
Week 3 = 110 × 1.08 = 118.8
This is the behavior I want it to follow. 

This doesn't actually need to be recursive. You can just multiply the trendline values and apply it to the last actual POS Units value.

Here's an ugly but working example DAX measure:

Projected POS Units = 
SUMX (
    VALUES ( Sales[Customer Name] ),
    VAR _MaxYear = MAX ( Sales[Planning Year] )
    VAR _MaxWeek = MAX ( Sales[Week Number] )
    VAR _Customer = Sales[Customer Name]
    VAR _AllWeeks =
        CALCULATETABLE (
            SELECTCOLUMNS ( 
                Sales,
                Sales[Planning Year],
                Sales[Week Number],
                Sales[POS Units],
                Sales[Trendline Value]
            ),
            ALLSELECTED ( Sales ),
            Sales[Customer Name]  = _Customer,
            Sales[Planning Year] <= _MaxYear,
            Sales[Week Number]   <= _MaxWeek
        )
    VAR _LastUnitsRow =
        TOPN (
            1,
            FILTER ( _AllWeeks, NOT ISBLANK ( Sales[POS Units] ) ),
            Sales[Planning Year], DESC,
            Sales[Week Number], DESC
        )
    VAR _LastUnits = MAXX ( _LastUnitsRow, Sales[POS Units] )
    VAR _Multiplier =
        PRODUCTX (
            FILTER ( _AllWeeks, ISBLANK ( Sales[POS Units] ) ),
            Sales[Trendline Value]
        )
    VAR _AddCols =
        ADDCOLUMNS (
            _AllWeeks,
            "ProjUnits",
                IF (
                    ISBLANK ( Sales[POS Units] ),
                    _LastUnits * _Multiplier,
                    Sales[POS Units]
                )
        )
    VAR _Result =
        SUMX (
            FILTER (
                _AddCols,
                Sales[Planning Year] = _MaxYear &&
                Sales[Week Number] = _MaxWeek
            ),
            [ProjUnits]
        )
    RETURN
        _Result
)

 

AlexisOlson_0-1755792345259.png

 

Hi Alexis, 

 

Thanks so much for this. This looks to work exactly how I want to show it. I am struggling to get the out still though as I think my DAX is having a hard to iterating rows. Here is the DAX I added and the out put I received (Only rollups for completed/past weeks that only match the actuals). I have mutiple materials in my POS sales table so not sure if the filter is not working correctly. 

Projected POS Units (Fabirc) =
SUMX (
    VALUES ( 'POS and TrendLine Merged Table'[Alternate Customer Name] ),
    VAR _MaxYear = MAX ( 'POS and TrendLine Merged Table'[Planning Year] )
    VAR _MaxWeek = MAX ( 'POS and TrendLine Merged Table'[Week Number])
    VAR _Customer = 'POS and TrendLine Merged Table'[Alternate Customer Name]
    VAR _AllWeeks =
        CALCULATETABLE (
            SELECTCOLUMNS (
                'POS and TrendLine Merged Table',
                'POS and TrendLine Merged Table'[Planning Year],
                'POS and TrendLine Merged Table'[Week Number],
                'POS and TrendLine Merged Table'[POS Units],
                'POS and TrendLine Merged Table'[Trendline Value]
            ),
            ALLSELECTED ( 'POS and TrendLine Merged Table' ),
            'POS and TrendLine Merged Table'[Alternate Customer Name]  = _Customer,
            'POS and TrendLine Merged Table'[Planning Year] <= _MaxYear,
            'POS and TrendLine Merged Table'[Week Number]   <= _MaxWeek
        )
    VAR _LastUnitsRow =
        TOPN (
            1,
            FILTER ( _AllWeeks, NOT ISBLANK ( 'POS and TrendLine Merged Table'[POS Units] ) ),
            'POS and TrendLine Merged Table'[Planning Year], DESC,
            'POS and TrendLine Merged Table'[Week Number], DESC
        )
    VAR _LastUnits = MAXX ( _LastUnitsRow, 'POS and TrendLine Merged Table'[POS Units] )
    VAR _Multiplier =
        PRODUCTX (
            FILTER ( _AllWeeks, ISBLANK ( 'POS and TrendLine Merged Table'[POS Units] ) ),
            'POS and TrendLine Merged Table'[Trendline Value]
        )
    VAR _AddCols =
        ADDCOLUMNS (
            _AllWeeks,
            "ProjUnits",
                IF (
                    ISBLANK ( 'POS and TrendLine Merged Table'[POS Units] ),
                    _LastUnits * _Multiplier,
                    'POS and TrendLine Merged Table'[POS Units]
                )
        )
    VAR _Result =
        SUMX (
            FILTER (
                _AddCols,
                'POS and TrendLine Merged Table'[Planning Year] = _MaxYear &&
                'POS and TrendLine Merged Table'[Week Number] = _MaxWeek
            ),
            [ProjUnits]
        )
    RETURN
        _Result
)

 

Current Output - Projected Units.PNG

I broke it down to a singular item and am now getting projections but they are coming in super high (assume summed for the material that exists from week 1 to 52 for mutiple customers) 

 

bbass82_0-1755799605080.png

 

It needs to be set to iterate at the right granularity. I think you may need to iterate over Material as well.

Projected POS Units = 
SUMX (
    SUMMARIZE (
        'POS and TrendLine Merged Table',
        'POS and TrendLine Merged Table'[Customer Name],
        'POS and TrendLine Merged Table'[Material]
    ),
    VAR _MaxYear = MAX ( 'POS and TrendLine Merged Table'[Planning Year] )
    VAR _MaxWeek = MAX ( 'POS and TrendLine Merged Table'[Week Number] )
    VAR _Customer = 'POS and TrendLine Merged Table'[Customer Name]
    VAR _Material = 'POS and TrendLine Merged Table'[Material]
    VAR _AllWeeks =
        CALCULATETABLE (
            SELECTCOLUMNS ( 
                'POS and TrendLine Merged Table',
                'POS and TrendLine Merged Table'[Planning Year],
                'POS and TrendLine Merged Table'[Week Number],
                'POS and TrendLine Merged Table'[POS Units],
                'POS and TrendLine Merged Table'[Trendline Value]
            ),
            ALLSELECTED ( 'POS and TrendLine Merged Table' ),
            'POS and TrendLine Merged Table'[Customer Name]  = _Customer,
            'POS and TrendLine Merged Table'[Material]       = _Material,
            'POS and TrendLine Merged Table'[Planning Year] <= _MaxYear,
            'POS and TrendLine Merged Table'[Week Number]   <= _MaxWeek
        )
    VAR _LastUnitsRow =
        TOPN (
            1,
            FILTER ( _AllWeeks, NOT ISBLANK ( 'POS and TrendLine Merged Table'[POS Units] ) ),
            'POS and TrendLine Merged Table'[Planning Year], DESC,
            'POS and TrendLine Merged Table'[Week Number], DESC
        )
    VAR _LastUnits = MAXX ( _LastUnitsRow, 'POS and TrendLine Merged Table'[POS Units] )
    VAR _Multiplier =
        PRODUCTX (
            FILTER ( _AllWeeks, ISBLANK ( 'POS and TrendLine Merged Table'[POS Units] ) ),
            'POS and TrendLine Merged Table'[Trendline Value]
        )
    VAR _AddCols =
        ADDCOLUMNS (
            _AllWeeks,
            "ProjUnits",
                IF (
                    ISBLANK ( 'POS and TrendLine Merged Table'[POS Units] ),
                    _LastUnits * _Multiplier,
                    'POS and TrendLine Merged Table'[POS Units]
                )
        )
    VAR _Result =
        SUMX (
            FILTER (
                _AddCols,
                'POS and TrendLine Merged Table'[Planning Year] = _MaxYear &&
                'POS and TrendLine Merged Table'[Week Number]   = _MaxWeek
            ),
            [ProjUnits]
        )
    RETURN
        _Result
)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.