cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
leo_89
Post Prodigy
Post Prodigy

Button for average for last year, 6 months, and 3 years

Hi there,

I want to create three buttons on my dashboard: one for average sale for last 6 months, second for an average sale of last 1 year and the last one for average sale for 5 years. I am not sure how to create buttons on power BI and how to associate action to calculate average sales. Any guidance would be really appreciated.

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@leo_89 ,

for measure slicer
https://radacad.com/change-the-column-or-measure-value-in-a-power-bi-visual-by-selection-of-the-slic...
https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/50...
https://www.youtube.com/watch?v=vlnx7QUVYME

 

Rolling with a date calendar

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH)) 
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH))  

Rolling 30 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX(Sales[Sales Date]),-30,Day))  

Rolling 365 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],today(),-365,Day))  
Rolling 1 year = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],today(),-12,Month))  

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

View solution in original post

3 REPLIES 3
Eyelyn9
Community Support
Community Support

Hi @leo_89 ,

According to my understanding, you want to display the average dynamically using buttons, right?

For my test, you could follow my steps:

 

1.Create measure for different time periods:

last6month =
CALCULATE (
    AVERAGE ( 'Table'[Sale] ),
    DATEDIFF ( 'Table'[Date], NOW (), DAY ) <= 6 * 30
)
last1year =
CALCULATE (
    AVERAGE ( 'Table'[Sale] ),
    DATEDIFF ( 'Table'[Date], NOW (), DAY ) <= 365
)
last5year =
CALCULATE (
    AVERAGE ( 'Table'[Sale] ),
    DATEDIFF ( 'Table'[Date], NOW (), DAY ) <= 5 * 365
)

2.Due to the measure cannot be used as X-axis, so you could create a new column with a value of "last 6 month" ,"last 1 year","last 5 year".Then use the column as X-axis to create a column chart. And create a slicer for it.

1.PNG

 

3.Then use Switch() to sum values, and create a visual like this:

for switch =
SWITCH (
    SELECTEDVALUE ( Period[period name] ),
    "last 6 month", [last6month],
    "last 1 year", [last1year],
    "last 5 year", [last5year]
)

2.PNG

 

4.Select the value in slicer and then add Bookmark for the visual.

3.PNG

 

5.Add Buttons for bookmarks by assigning bookmark in Action tabs under Selection pane, like this:

5.PNG

 

6.Repeat step4 and step5 for another two values. Now you could Ctrl+click to follow link.

Annotation 2020-08-11 174936.png

 

Is the result what you want? Hope to give me a reply. Thanks~

 

Best Regards,

Eyelyn Qin

 

 

Greg_Deckler
Super User
Super User

@leo_89 - Sounds like you want some kind of stacked visuals and then to use bookmarks to display the correct visual and hide the other visuals. So, create your bookmarks and then create the buttons you want and tie their action to the bookmarks.


@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop! Microsoft Hates Greg's Quick Measures
YouTube Channel! Microsoft Hates Greg
Check out my latest book!

amitchandak
Super User
Super User

@leo_89 ,

for measure slicer
https://radacad.com/change-the-column-or-measure-value-in-a-power-bi-visual-by-selection-of-the-slic...
https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/50...
https://www.youtube.com/watch?v=vlnx7QUVYME

 

Rolling with a date calendar

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH)) 
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH))  

Rolling 30 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX(Sales[Sales Date]),-30,Day))  

Rolling 365 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],today(),-365,Day))  
Rolling 1 year = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],today(),-12,Month))  

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.