Forum Discussion

cgaralde's avatar
cgaralde
Frequent Visitor
3 years ago
Solved

Filter Quantity on Week-to-date based on Slicer selection

Hi,   I am working on a personal project for work that requires a user to select a Week Number (W1 2023) and based on this slicer, it should show the current stock as of the last day of W1 2023.  R...
  • cgaralde's avatar
    cgaralde
    3 years ago

    amitchandak, thanks for the links that you provided.  It definitely pointed me to the right direction.

     

    I am able to solve my requirements by doing the following:

     

    I added a CURRENT DAY OFFSET COLUMN in power query using the following:

    Number.From([Date]) - Number.From(Date.From( DateTime.FixedLocalNow()))

    This gives me an integer value showing this:

     

     

     

     

    Based on this I made the following DAX statement:

    SOH =
    VAR currOffset = MAX(Dim_Trading_Calendar[Curr Day Offset])
    //Takes the maximum offset of the current selection in this case
    // -11 as my slicer selection was W8 2023
    VAR WTDSelection = CALCULATE(
    SUM(Fact_Stock_w_Cost[Qty]),
    //I wanted to sum the Qty Column from this table
    ALL(Dim_Trading_Calendar),
    //I wanted to clear all filters from my calendar table, in this case current
    //selection is Week 8 2023
    Dim_Trading_Calendar[Curr Day Offset] <= currOffset
    //I apply a new filter where the offset is less than or equal to -11.
    //It gives me a filter of all columns prior and including the 26 FEB 2023
    )
    RETURN WTDSelection

     

    I hope this helps someone else. 🙂