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.
Hi,
I`m trying to create a Slicer with Last Month, Last 3 months and Overall.
I tried one Dax formula described here: Power BI – Time Period Slicer for Last 7 Days,Last 30 Days.. – Analytics Avenue
DatePeriod =
UNION (
ADDCOLUMNS( SUMMARIZE( CALCULATETABLE('Date' , DATESBETWEEN('Date'[Date],today()-07+1,today()) ), 'Date'[Date]),"Period","Last 07 Days") ,
ADDCOLUMNS( SUMMARIZE( CALCULATETABLE('Date' , DATESBETWEEN('Date'[Date],today()-14+1,today()) ), 'Date'[Date]),"Period","Last 14 Days") ,
ADDCOLUMNS( SUMMARIZE( CALCULATETABLE('Date' , DATESBETWEEN('Date'[Date],today()-30+1,today()) ), 'Date'[Date]),"Period","Last 30 Days") ,
ADDCOLUMNS( SUMMARIZE( CALCULATETABLE('Date' , DATESBETWEEN('Date'[Date],today()-90+1,today()) ), 'Date'[Date]),"Period","Last 90 Days") ,
ADDCOLUMNS( SUMMARIZE( CALCULATETABLE('Date'), 'Date'[Date]),"Period","Overall")
)
But it doesn`t work for me. My dates are formated as only M+Y (no days):
01.01.2015 00:00:00 |
01.02.2015 00:00:00 |
Do you know any solution or workaround?
Many thanks,
Jakub
When i need to filter last periods i usually add a column in dax like this:
DateFilter = IF(Sales[Date] >= DATE(YEAR(DATEADD(LASTDATE(ALL(TableDate[Date])) , -4 , MONTH)),
MONTH(DATEADD(LASTDATE(ALL(TableDate[Date])) , -4 , MONTH)),
1),
"Last four months",
IF (AND(
YEAR(Sales[Date]) = YEAR(NOW()),
MONTH(Sales[Date]) = MONTH(NOW())
),
"Last month",
"More than 4 months"
)
With the logic you can add different ways. The example contains last 4 months and last month.
Regards,
P/D I hope the DAX is okay I didn't have time to run it.
Happy to help!
Hi @ibarrau,
the problem is my periods can overlap each other.
I would like to have last month, last 3 months, last 6 months and overall. I think tough your formula won`t apply there 😞
Did you try the relative date slicer of the new release of power bi? It is a preview feature you have to activate in power bi desktop. That is the only aproach to have only one column specify as you need.
You can read more in the release notes:
https://powerbi.microsoft.com/en-us/blog/power-bi-desktop-may-feature-summary/#relativeDateSlicer
Regards, hope this help or you may need more columns I think.
Happy to help!
Yes, it`s working acceptably but I wanted to build more flexible slicer based on data I am providing. For instance, no day drill option when I have only month-based data. By relative date slicer it`s not possible.
thank you for your ideas anyway!
Jakub
Dear @JakubHa,
Have you try What-If parameter?
You can create new Parameter type Number, it'll use for selected number and refresh data with last 1,2,3,....9 month.
Parameter Value = SELECTEDVALUE(Parameter[Parameter], 3)
Then make measure, filter it by some Operation with "Parameter Value".
Topic about Parameter: https://powerbi.microsoft.com/en-us/blog/power-bi-desktop-august-2017-feature-summary/#whatIf
If you need a day drill option, you can use Custom Visual "TimeBrush". You can drag mouse to select a range or move it.
Hi @Anonymous,
Thanks for your suggestion! I`ll try it out and let you know if that works fine for me 🙂
Greetings,
Jakub
Dear @JakubHa,
Sure, I'm waiting for your result. If you get problem, we can discuss more 🙂
Regards,
ManNVSM.
I suggest you add a column for previous 3 months day in Query Editor.
Date.AddMonths(DateTime.Date(DateTime.LocalNow()),-3)
Then add a column to tage if the dates is within 3 months.
If Within 3 months = IF ( Table[Date] >= DATE ( YEAR ( Table[Previous 3 months Day] ), MONTH ( Table[Previous 3 months Day] ), 1 ) && Table[Date] <= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ), 1, 0 )
Now you can use above column to filter your table.
Regards,
Hi @v-sihou-msft,
thanks for your reply! It seems to work fine for last 3 months only. Is there any way to extend this field into last month, last 3 months, last 6 months and all months?
Many thanks for your support,
Jakub
Add a new column in Power Query (Query Editor):
= Table.AddColumn(YOURLASTSTEP, "MonthDiff", each (Date.Year([Date])-1)*12+Date.Month([Date]) - ((Date.Year(DateTime.LocalNow())-1)*12+ Date.Month(DateTime.LocalNow())) )
The code calculates the differenz between today and the date in your column in months.
Then you'll use this new column as a slicer.
Hope this helps.
Hello @Anonymous,
I`ve got this error: "Expression.Error: The name 'YOURLASTSTEP' wasn't recognized. Make sure it's spelled correctly."
Appreciate your help,
Jakub
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
95 | |
76 | |
65 | |
51 |
User | Count |
---|---|
146 | |
109 | |
106 | |
88 | |
61 |