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
ngg4686
Frequent Visitor

Timeline slicer & variable months

I'm using this visualization and I have down pat showing "current selected" data.  What I'm wondering how to do is on the same page - show the current selected time period from the slicer (say in a bar graph) and have a bar right next to it that shows the previous unit of time that is selected.  For instance if I have the month of August selected, I would want this bar graph to show August and July next to each other.  If I changed the slicer to show year, I would want 2016 and 2015 to show on the graph.  Is there a way to write DAX that goes back one time period based on what slice is selected from the slicer?

4 REPLIES 4
v-yuezhe-msft
Employee
Employee

Hi @ngg4686,

Agree with CahabaData. When creating a measure to show data of previous year/quarter/month, you can use PREVIOUSYEAR function, PREVIOUSQUARTER function and PREVIOUSMONTH function . There is an example about how to show data of current quarter and previous quarter in this article  for your reference.

Besides, in your scenario, why not directly select date ranges in Timeline slicer and combine built-in date hierarchy of Power BI Desktop to show data in your graph? An example is shown in the following screenshot.
1.PNG

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
CahabaData
Memorable Member
Memorable Member

I believe one cannot put the cart in front of the horse - or in this case the slicer in front of the calculation - - - sorry for bad joke.....

 

In your data model where you now have value 'X' - you want also a measure/column along side with value 'X-prior year' (or whichever period).  So that X and X-prior are side by side values.  Then if you filter on X the X-prior value is available to you.

 

 

www.CahabaData.com

Is there a way that I can set a dynamic date heriarchy?  If I have "week" selected, I want a bar graph to show week over week what is going on.  If I change it to "Month" I want to see data aggregated by month.  Basically in the bar graph "Axis" I would want something that looks at slicer to determine how to set the heirarchy.  

When your granular row value is a date - the Power BI features can expand that date into its fields for week, month, quarter values. 

 

You can use those period values for filtering & aggregating

 

Any value fields of that data model can be aggregated by those periods.

 

so I believe you can get what you seek if I understand your question......

www.CahabaData.com

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