Forum Discussion

Elliott's avatar
Elliott
Advocate II
10 years ago
Solved

Group by Data Ranges

Hi All,   Need a little assistance with what I presume will require a DAX query.   I currently have a column named 'Days Aging' with the following query: Days Aging = DATEDIFF([Date],TODAY(),DAY)...
  • konstantinos's avatar
    10 years ago

    Elliott First you need a table with the text that you need on the slicer with also a column for sorting and getting the value.

     

     

    Use "Enter Data" to create a table

     

    Period                 Sort
    Today's Data            1
    Last 7 Days             2
    Last 30 Days            3

     

    The table won't have any relantionship with others ( let's call it "Periods")

     

    Create a new measure that will change based on the slicer selection

     

    VariablePeriod =
    SWITCH (
        MIN ( Periods[Sort] );
        1; CALCULATE ( [yourmeasure]; FILTER ( Table; Table[Days Aging] = 1 ) );
        2; CALCULATE (
            [yourmeasure];
            FILTER ( Table; Table[Days Aging] > 1 && Table[Days Aging] <= 7 )
        );
        3; CALCULATE ( [yourmeasure]; FILTER ( Table; Table[Days Aging] > 30 ) )
    )

     Now add as slicer the Periods field from "Periods Table" and use the [VariablePeriods] for your graphs. 

    Notice that if there is no selection on the slicer it will calculate the MIN( Periods[Sort]) which is Today's. You can use MAX if you want to show all data.

     

    *I am writing without pbix open, so maybe some mispelling on formula.

    * If you go to powerpivotpro.com and search " disconnected slicer" there are many and great posts on the subject