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
Anonymous
Not applicable

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
amitchandak
Super User
Super User

@Anonymous , 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-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , 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-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

vanessafvg
Super User
Super User

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])))




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

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)

Hi @Anonymous ,

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.

Anonymous
Not applicable

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
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.