Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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:
(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:
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
Solved! Go to Solution.
@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.
@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.
Proud to be a Super User!
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.
Finaly, I just deleted the slicer and put it back again, and the formula I first used worked. Thanks a lot for your help
User | Count |
---|---|
127 | |
108 | |
100 | |
63 | |
62 |
User | Count |
---|---|
136 | |
113 | |
102 | |
71 | |
60 |