Forum Discussion

Ajithrjaa's avatar
Ajithrjaa
Frequent Visitor
2 years ago
Solved

Data Filter Condition

Hi , 

I have a some quey please add some valid use casess on this scenarion.

Case : Max Year is 2024 from that I have a min date 1/4/2024 and Max Date 7/11/2024 this is the data range for Prevoius Years.
I would Like Put a one Condition Previous Years also Baesd on this dynamics Min and Max DDMM.

the MinDate and Max Date range should be a Maxdate Year. 

DateSalesYear
11/2/2022612022
7/27/2022332022
8/18/2022672022
11/24/2022942022
7/5/2022932022
1/19/2022512022
8/22/2022672022
5/31/2022692022
8/4/2022112022
8/4/2022462022
4/4/202282022
1/11/202262022
1/15/2022362022
9/23/2022632022
9/11/2022942022
11/13/2022292022
5/22/20231002023
10/26/2023782023
12/5/2023842023
7/13/202352023
7/7/2023852023
11/24/2023512023
2/7/2023142023
8/29/2023442023
5/31/2024242024
1/4/2024362024
3/9/2024432024
2/1/2024872024
7/11/202482024
2/16/2024192024


Output Like 

DateSalesYearFlag
5/31/2024242024Y
1/4/2024362024Y
3/9/2024432024Y
2/1/2024872024Y
7/11/202482024Y
2/16/2024192024Y
5/22/20231002023Y
10/26/2023782023N
12/5/2023842023N
7/13/202352023N
7/7/2023852023Y
11/24/2023512023N
2/7/2023142023Y
8/29/2023442023N




  • Step 0: I use your data. (Date:yyyy/mm/dd)

     

    Step 1: I make a 'Calendar' table and add a relationship.

    Calendar = CALENDAR(FIRSTDATE('DATA'[Date]),LASTDATE('DATA'[Date]))

     

    Step 2: I make a 'Sel-Cal' table and make a 'Sel-Cal' slicer.

    Sel-Cal = SUMMARIZE('DATA','DATA'[Year])

    - Slicer -

     

    Step 3: I make many measures below.

    M_Flag = IF(MAX('DATA'[Date])<=[M_Maxx_Date_ALL]&&MIN('DATA'[Date])>=[M_Minx_Date_ALL],"Y",IF(MAX('DATA'[Date])<=[M_Maxx_Date_Pre_ALL]&&MIN('DATA'[Date])>=[M_Minx_Date_Pre_ALL],"Y","N"))

     

    M_Maxx_Date_ALL = MAXX(FILTER(ALL('DATA'),'DATA'[Year]=[M_Year_Sel]),'DATA'[Date])

     

    M_Maxx_Date_Pre_ALL = MAXX(FILTER(ALL('Calendar'),(YEAR('Calendar'[Date])=[M_Year_Sel]-1)&&('Calendar'[Date]<=[M_Max_YMD_Pre])),'Calendar'[Date])

     

    M_Minx_Date_ALL = MINX(FILTER(ALL('DATA'),'DATA'[Year]=[M_Year_Sel]),'DATA'[Date])

     

    M_Minx_Date_Pre_ALL = MINX(FILTER(ALL('Calendar'),(YEAR('Calendar'[Date])=[M_Year_Sel]-1)&&('Calendar'[Date]>=[M_Min_YMD_Pre])),'Calendar'[Date])

     

    M_Max_YMD_Pre = DATE([M_Year_Sel]-1,[M_Max_M_ALL],[M_Max_D_ALL])

     

    M_Min_YMD_Pre = DATE([M_Year_Sel]-1,[M_Min_M_ALL],[M_Min_D_ALL])

     

    Step 4: I make a matrix.

     

3 Replies

  • Hi Ajithrjaa ,

     

    I am not exactly sure what you are trying to achieve but if you want to check whether the current period (month and year) has data in the previous year (previous year and month), you can try the calculated column below:

    Flag = 
    VAR PreviousYearsPeriod =
        FORMAT ( EDATE ( 'Table'[Date], -12 ), "YYYYMM" )
    VAR PreviousYearsValue =
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                ALL ( 'Table' ),
                FORMAT ( 'Table'[Date], "YYYYMM" ) = PreviousYearsPeriod
            )
        )
    RETURN
        IF ( NOT ( ISBLANK ( PreviousYearsValue ) ), "Y", "N" )
    

     

     

  • Ajithrjaa's avatar
    Ajithrjaa
    Frequent Visitor

    danextian  thanks for the Quick Response.

    my Cenario which is date range Min and Max dates from the Max Year.  this data range should be a Previous Physical Year.
    this give some example based on month Basic

     




  • Step 0: I use your data. (Date:yyyy/mm/dd)

     

    Step 1: I make a 'Calendar' table and add a relationship.

    Calendar = CALENDAR(FIRSTDATE('DATA'[Date]),LASTDATE('DATA'[Date]))

     

    Step 2: I make a 'Sel-Cal' table and make a 'Sel-Cal' slicer.

    Sel-Cal = SUMMARIZE('DATA','DATA'[Year])

    - Slicer -

     

    Step 3: I make many measures below.

    M_Flag = IF(MAX('DATA'[Date])<=[M_Maxx_Date_ALL]&&MIN('DATA'[Date])>=[M_Minx_Date_ALL],"Y",IF(MAX('DATA'[Date])<=[M_Maxx_Date_Pre_ALL]&&MIN('DATA'[Date])>=[M_Minx_Date_Pre_ALL],"Y","N"))

     

    M_Maxx_Date_ALL = MAXX(FILTER(ALL('DATA'),'DATA'[Year]=[M_Year_Sel]),'DATA'[Date])

     

    M_Maxx_Date_Pre_ALL = MAXX(FILTER(ALL('Calendar'),(YEAR('Calendar'[Date])=[M_Year_Sel]-1)&&('Calendar'[Date]<=[M_Max_YMD_Pre])),'Calendar'[Date])

     

    M_Minx_Date_ALL = MINX(FILTER(ALL('DATA'),'DATA'[Year]=[M_Year_Sel]),'DATA'[Date])

     

    M_Minx_Date_Pre_ALL = MINX(FILTER(ALL('Calendar'),(YEAR('Calendar'[Date])=[M_Year_Sel]-1)&&('Calendar'[Date]>=[M_Min_YMD_Pre])),'Calendar'[Date])

     

    M_Max_YMD_Pre = DATE([M_Year_Sel]-1,[M_Max_M_ALL],[M_Max_D_ALL])

     

    M_Min_YMD_Pre = DATE([M_Year_Sel]-1,[M_Min_M_ALL],[M_Min_D_ALL])

     

    Step 4: I make a matrix.