Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

DAX help on filter context

Hi Team,   Please can you help me on below requirement.   I have Table A with below fields Name    Date                    Amount A          2022/11/23          10 A          2022/12/20       ...
  • v-yueyunzh-msft's avatar
    v-yueyunzh-msft
    3 years ago

    Hi , Anonymous 

    According to your description ,  you want to “CASE WHEN (DATE1 >= '2022-11-21 00:00' AND DATE2  < '2022-11-22 00:00' ) THEN AMOUNT”.

    Here are the steps you can refer to:

    (1)My test data is the same as yours.

    (2)For your need , i recommend you to create a date table as slicer instead of using the date column in your table. You can click “New Table” and enter this:

     

    Date = CALENDAR( FIRSTDATE('Table'[Date1]),LASTDATE('Table'[Date1]))

     

    And we do not need to create relationship between two tables.

    (3)We can click “New Measure”  to create a measure:

     

    Measure = var  _min = MIN('Date'[Date])
    
    var _max = MAX('Date'[Date])
    
    var _t =FILTER('Table' , 'Table'[Date1]>= _min && 'Table'[Date1] <_max)
    
    return
    
    SUMX(_t,[Amount])

     

    (4)Then we can put the ’Date‘[Date] on the sliver visual and the [Name] and the measure  on the visual and we will meet your need :

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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