Forum Discussion

ash_best_'s avatar
ash_best_
New Member
1 year ago
Solved

DAX last 4 weeks

Hi I want to create a visual, line chart that shows me last 4 weeks of sellthrough (sales/stock). My sales data is captured daily and stock every Monday. I also have a date range slicer. Regardless o...
  • v-karpurapud's avatar
    v-karpurapud
    1 year ago

    Hi ash_best_ 

    1. Create a disconnected Week table:

    WeekCalendar =
    
    SUMMARIZE(
    
        'Date',
    
        'Date'[WeekStart],  
        'Date'[YearWeek]   
    
    )

     

    2. Derive the max week from the slicer selection:

    MaxWeek =
    
    CALCULATE(
    
        MAX('Date'[YearWeek]),
    
        ALLSELECTED('Date')  
    )
    
    

     

    3. Sell-through by week measure

    Put this measure on the visual Y-axis. It uses the WeekCalendar row context (the axis), pulls sales & Monday stock for that week from the actual tables (ignoring slicer min), and returns BLANK() when the week is not among the last 4 weeks relative to MaxWeek.

    SellThrough_ByWeek =
    
    VAR _ThisWeek = SELECTEDVALUE(WeekCalendar[YearWeek])
    
    VAR _WeekStart = SELECTEDVALUE(WeekCalendar[WeekStart])  
    
    VAR _MaxWeek = [MaxWeek]
    
    
    
    VAR _Sales =
    
        CALCULATE(
    
            SUM(Sales[SalesAmount]),
    
            FILTER( ALL('Date'), 'Date'[YearWeek] = _ThisWeek )
    
        )
    
    
    
    VAR _Stock =
    
        CALCULATE(
    
            SUM(Stock[StockQty]),
    
            FILTER( ALL('Date'), 'Date'[Date] = _WeekStart )  
    
        )
    
    
    
    VAR _Result = DIVIDE(_Sales, _Stock)
    
    
    
    RETURN
    
    IF( _ThisWeek >= _MaxWeek - 3 && _ThisWeek <= _MaxWeek, _Result, BLANK() )
    
    

     

    Set WeekCalendar[WeekStart] as the X-axis (sorted ascending) and use SellThrough_ByWeek on the Y-axis. Keep your Date slicer on Date[Date], as it drives the [MaxWeek] measure. No additional visual-level filters are required, though you may optionally filter out blank SellThrough_ByWeek values for clarity.

    If this still does not resolve your scenario, kindly share a sample PBIX file with masked or dummy data so we can better understand your data model and assist you in the best possible way.

    Regards,
    Microsoft Fabric Community Support Team.