Forum Discussion

DubD's avatar
DubD
Frequent Visitor
4 years ago
Solved

Filter a table that contains one date field based on multiple date ranges and display chosen range

I'm looking to display an aggregation of sales data based on the SalesDate where the user specifies the following filters:    Start Date Current Date End Date   The table should show total sale...
  • v-easonf-msft's avatar
    4 years ago

    Hi, DubD 

    The expected result you provide seems to be wrong.

     

     You can try steps as below:

    1.Enter a Table:

    2.create measure like:

    Range = 
    SWITCH(SELECTEDVALUE(Scenario[Scenario]),
     "Scenario 1",[Start Date]&" through "&[Current Date],
     "Scenario 2",[Start Date -1yr]&" through "&[Current Date -1yr],
     "Scenario 3",[Current Date -1yr]&" through "&[End Date -1yr],
     "Scenario 4",[Start Date -2yr]&" through "&[Current Date -2yr],
      "Scenario 5",[Current Date -2yr]&" through "&[End Date -2yr]
      )
    Scenario = SWITCH(
        TRUE(),
        [Start Date]<=[Sale Date]&&[Start Date]<[Current Date],"Scenario 1",
        [Start Date -1yr]<=[Sale Date]&&[Sale Date]<[Current Date -1yr],"Scenario 2",
        [Current Date -1yr]<=[Sale Date]&&[Sale Date]<=[End Date -1yr],"Scenario 3",
        [Start Date -2yr]<=[Sale Date]&&[Sale Date]<[Current Date -2yr],"Scenario 4",
        [Current Date -2yr]<=[Sale Date]&&[Sale Date]<[End Date -2yr],"Scenario 5","Excluded"
    )
    Total sales = CALCULATE(SUM('Table'[NetSales]),FILTER('Table','Table'[ID]=MAX('Table'[ID])&&[Scenario]=SELECTEDVALUE(Scenario[Scenario]))
    )

    Note: Scenario[Scenario] is indispensable in this table visual, otherwise other column data will be summarized, but you can reduce the column width to 0 to hide it. (The 'text wrap' option needs to be turned off)

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.