Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DRusso
New Member

Slicer for Custom Business Year and Month Range

Hello,

 

I'd like to create a slicer that allows users to filter by the current active business year. The custom range would always be the 1st day of the selected month and year, rolling back to the 2nd day of the same month in the previous year. Example below:

 

DRusso_0-1689108305952.png

With the data filtered as above, the dates displayed should be:

January 2, 2022 - January 1, 2023

 

Another example - If 2020 and May were selected in the slicers, the dates displayed should be:

May 2, 2019 - May 1, 2020

 

I already have a Dates table set-up using CALENDARAUTO() with a relationship to my sales table. 

 

Thanks a bunch!

DR

 

 

 

1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @DRusso ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_1-1689232636669.png

Table2:

vbinbinyumsft_2-1689232655277.png

Sales:

vbinbinyumsft_0-1689232619614.png

2. create a measure with below dax formula

Measure =
VAR _year =
    SELECTEDVALUE ( 'Table'[Year] )
VAR _month =
    SELECTEDVALUE ( 'Table 2'[Month] )
VAR cur_date =
    SELECTEDVALUE ( Sales[Date] )
VAR tmp =
    CALENDAR ( DATE ( _year - 1, _month, 2 ), DATE ( _year, _month, 1 ) )
RETURN
    SWITCH (
        TRUE (),
        OR (
            NOT ( HASONEVALUE ( 'Table'[Year] ) ),
            NOT ( HASONEVALUE ( 'Table 2'[Month] ) )
        ), 1,
        cur_date IN tmp, 1
    )

 

3. add slicer visual with Table and Table2 field, add a Table visual with Sales field, add measure to table visual filter pane and set

Animation11.gif

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-binbinyu-msft
Community Support
Community Support

Hi @DRusso ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_1-1689232636669.png

Table2:

vbinbinyumsft_2-1689232655277.png

Sales:

vbinbinyumsft_0-1689232619614.png

2. create a measure with below dax formula

Measure =
VAR _year =
    SELECTEDVALUE ( 'Table'[Year] )
VAR _month =
    SELECTEDVALUE ( 'Table 2'[Month] )
VAR cur_date =
    SELECTEDVALUE ( Sales[Date] )
VAR tmp =
    CALENDAR ( DATE ( _year - 1, _month, 2 ), DATE ( _year, _month, 1 ) )
RETURN
    SWITCH (
        TRUE (),
        OR (
            NOT ( HASONEVALUE ( 'Table'[Year] ) ),
            NOT ( HASONEVALUE ( 'Table 2'[Month] ) )
        ), 1,
        cur_date IN tmp, 1
    )

 

3. add slicer visual with Table and Table2 field, add a Table visual with Sales field, add measure to table visual filter pane and set

Animation11.gif

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-binbinyu-msft,

 

Sorry about the late reply, was away for a couple weeks and just came back to this. This worked great! Is there anyway to allow for the data to be displayed by year only and compared to the previous year?

 

I'm able to achieve a comparison the the previous year using the SAMEPERIODLASTYEAR measure, but only if I use the the full date column in the table.  

DRusso_0-1690989843479.png

 

I'd like to be able to display the data by year only, using the custom range filter you built in a table and a bar chart. Simple example below but these are ignoring the filters. 

 

DRusso_1-1690990126837.png

Best,

DR

 

 

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.