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
ShivaPrasad1
Helper I
Helper I

Passing month and year parameters to filter the visuals.

Hello Team,

 

I have 3 years of data and counting in my data set. Date column is in the format of 2018.02, 2018.03 etc..I should have two slicers to select year and month. Based on the selection of slicers I need to show previous 12 months of data. Can I achieve this using paramters? If yes, can you show me the way please. It should be flexible to change the values as well to view different range of date values of data.

 

Also appreciated, if the solution can work for Power BI service as well.

 

Ex: 

Parameter 1 : 2017, Paramter 2: 08

 

Output should be like:

2016.09 to 2017.08 data

Thanks in advance.

 

Regards,

Shiva

 

3 REPLIES 3
v-cherch-msft
Employee
Employee

Hi @ShivaPrasad1

 

You may try to create measure as below. Here is the reference for you.

https://community.powerbi.com/t5/Desktop/Show-last-13-months-based-on-user-single-slicer-selection/m...

 

Measure  =
VAR par1 =
    SELECTEDVALUE ( 'Slicer'[Year] )
VAR par2 =
    SELECTEDVALUE ( 'Slicer'[Month] )
RETURN
    CALCULATE (
        MAX ( 'Table'[YearMonth] ),
        FILTER (
            'Table',
             'Table'[Date]  >= EDATE ( DATE ( par1, par2, 31 ), -11 )
                &&  'Table'[Date]  <= DATE ( par1, par2, 31 )
        )
    )

Sample file is here.

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ShivaPrasad1
Helper I
Helper I

Hello Team,

 

I have 3 years of data and counting in my data set. Date column is in the format of 2018.02, 2018.03 etc..I am having two slicers to select year and month. Based on the selection of slicers I need to show previous 12 months of data. 

 

Also appreciated, if the solution can work for Power BI service as well.

 

Ex: 

Slicer 1 : 2017, Slicer 2: 08

 

Output should be like:

2016.09 to 2017.08 data

Thanks in advance.

 

Regards,

Shiva

 

Greg_Deckler
Super User
Super User

Basically something along the lines of:

 

Measure =
VAR __param1 = MAX('Table'[Parameter 1])
VAR __param2 = MAX('Table'[Parameter 2])
RETURN SUMX(FILTER('Table',([Year]>=__param1-1&&[Month>__param2)&&([Year]=__param1&&[Month]<=__param2)),[Data])

Tough to be specific without data. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors