Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Dynamic grouping according to the time range

Hi there,    I am using the Sample data "Financial" from Power BI sample dataset.    I have a dynamic date slicer for the sales date.    What I wanted to do is 1. select the last date from the...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi, Anonymous 

     

    You can try the following methods. The end month column was added to the original table.

    Measure = 
    Var _Maxselectdate = MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])
    Var _lastdate = EOMONTH(_Maxselectdate,-4)
    VAR _Curmonth = SELECTEDVALUE('financials'[End Month])
    VAR _Result = IF( _Curmonth <= _Maxselectdate && _Curmonth >= _lastdate, 1)
    Return
    _Result
    Measure Value = 
    Var _Maxselectdate = MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])
    VAR _Mindate = EOMONTH(_Maxselectdate,-1) + 1
    Var _maxmonthvalue = CALCULATE( SUM(financials[Sales]), 'financials'[Date] >= _Mindate && 'financials'[Date] <= _Maxselectdate)
    RETURN
    IF(NOT ISBLANK([Measure]) || ISBLANK(SELECTEDVALUE('financials'[End Month])), IF(ISBLANK(SELECTEDVALUE('financials'[End Month])),_maxmonthvalue,SUM(financials[Sales])))

    Please see the attached document.

     

    Best Regards,

    Community Support Team _Charlotte

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.