cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Regular Visitor

Date slicers that affects column differently

Hi,

 

I have a database where I need to filter what happened before a certain year, and what happened during that year. Here is a simplified version of what I need to do :

 

Let's say I have this data:

Capture.PNG

 

(Yes I sometimes have several entries from a single year).

And I have a slicer that filters by year. If the slicer was set to 2012, the result should be:

Capture.PNG

I tried unlinking the slicer from the table, and simply creating CALCULATE() functions that are filtered when date < selectedValues(Year) and the other being filtered when date = selectedValues(year), but it I simply had blanks for the amount before.

 

Thank you for your help

1 ACCEPTED SOLUTION
Super User IV
Super User IV

@Bilou9 , Make sure use separate Date or year table , selection should give you selected  year

 

example

this year = Sum('order'[Qty])

 

before year=
var _max = today()
var _max = maxx(allselected('Date'),'Date'[Date])
return
calculate(Sum('order'[Qty]),filter(all('Date'),'Date'[Year]<=_max))

 

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.



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

Proud to be a Super User!

View solution in original post

5 REPLIES 5
Super User IV
Super User IV

@Bilou9 , Make sure use separate Date or year table , selection should give you selected  year

 

example

this year = Sum('order'[Qty])

 

before year=
var _max = today()
var _max = maxx(allselected('Date'),'Date'[Date])
return
calculate(Sum('order'[Qty]),filter(all('Date'),'Date'[Year]<=_max))

 

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.



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

Proud to be a Super User!

View solution in original post

Super User I
Super User I

amount this year = CALCULATE(sum('Table'[sold]), FILTER('Table', 'Table'[yr] >= SELECTEDVALUE('Table'[yr])))

amount before =
var slicer = SELECTEDVALUE('Table'[yr])
return
CALCULATE(sum('Table'[sold]), FILTER(all('Table'), 'Table'[yr] < SELECTEDVALUE('Table'[yr])))




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I tried this
 
amount before =
var slicer = SELECTEDVALUE(Time_Dim[Date].[Année])
return CALCULATE(sum(sales[Qty]); filter(all(Time_Dim); Time_Dim[Date].[Année] < slicer))
 
Where the column Time_Dim[date] is the date and the column sales[qty] is the amount, and it only gives me blanks...😕
(année is the equivalent of year)
Community Support
Community Support

Hi @Bilou9 ,

In your formula, you quoted two table fields 'sales[Qty]' and 'Time_Dim[Date]'. If there is no relationship between these tables, you will not get the right result.

Not certain what does your dataset look like, is there any other field in your sales table like year.. However, if your sales table actually has year column, you can use the formula as @vanessafvg  mentioned to calculate directly.

Could you please consider sharing your sample table for further discussion?

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Finaly, I just deleted the slicer and put it back again, and the formula I first used worked. Thanks a lot for your help

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Wave Release 2

Check out the updates in Power BI.

Overview of Power BI 2020 release wave 2!

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors