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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Show data based on slicer selection

Hello All,

 

I have table where I am having daily data like date,sales,profit and discount.

 

My requirement is I need to show a slicer which have values like daily,weekly,monthly and Quarterly.

If the user selects daily I need to show last 30 days sales,profit and discount.

If the user selects Monthly I need to show last 12 months data.(Here I need to aggrigate data for monthly)

If the user selects Weekly I need to show last 12 Weeks data. (Here I need to aggrigate data for Weekly)

If the user selects Quarterly I need to show last 4 qtrs data. (Here I need to aggrigate data for qtrly)

 

So I created a table in power bi with these values and showing as slicer.

Not sure how to write the dax to calulate these.

 

 

Sample Data :

 

Sathvik123_0-1678883986617.png

 

Could any one please help on this

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Have these as the name of Date, Month , week and Qtr column, you want to display on axis

 

rolling 12 =  // Same for month and qtr
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = date(Year(_max), month(_max) -12, Day(_max))+1
BLANK())
return
CALCULATE([net] ,filter(Date, Date[Date] >= _min && Date[Date] <=_min))

 

 

days

=

var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = _max -30
BLANK())
return
CALCULATE([net] ,filter(Date, Date[Date] >= _min && Date[Date] <=_min))

 

 

for week you need use week rank column in date table

Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX('Date','Date'[Year Week],,ASC,Dense) //YYYYWW format

 

Last 12 weeks = CALCULATE(sum('Table'[Qty]), FILTER(('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-11 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

Now use the field parameter on the renamed column of date table and change the measure as suggested in blog

 

selected parameter code is important

Switch TOPN with Field Parameters: https://amitchandak.medium.com/switch-topn-with-field-parameters-299a0ae3725f

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Hi @amitchandak ,

 

In the below calculation what is meant by [net] ?

 

CALCULATE([net] ,filter(Date, Date[Date] >= _min && Date[Date] <=_min))

@Anonymous , here net is my measure. You can use your measure

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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