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 all.
I'm looking to be able to filter my data based on different date periods ie. YTD, current month, previous month. However, I would like to be able to select one of these from a drop down filter. is this possible?
Many thanks.
Solved! Go to Solution.
Hi @Dz6kb4
Sure. Just create a measure table and don't connect it to anything
The table may contain data like :
I called my table Date Range
ID Value -- -------- 1 This Month 2 Current Month 3 Last Month
Then add that table to a slicer but don't create any relationships between this table and your date table.
Then create a measure on your Date table that uses DAX to determine if your date is part of the grouping.
Date Range Filter = VAR ThisMonth = TODAY() VAR LastMonth = EOMONTH(TODAY(),-1) VAR PrevMonth = EOMONTH(TODAY(),-2) RETURN SWITCH( TRUE() , -- Current Month MAX('Date Range'[ID])=1 && MONTH(MAX('Dates'[Date])) = MONTH(ThisMonth) && YEAR (MAX('Dates'[Date])) = YEAR(ThisMonth) , 1 , -- Last Month MAX('Date Range'[ID])=2 && MONTH(MAX('Dates'[Date])) = MONTH(LastMonth) && YEAR (MAX('Dates'[Date])) = YEAR(LastMonth) , 1 , -- Last Month MAX('Date Range'[ID])=3 && MONTH(MAX('Dates'[Date])) = MONTH(PrevMonth) && YEAR (MAX('Dates'[Date])) = YEAR(PrevMonth) , 1 , -- ELSE 0)
Then just drag this measure in as a filter on your visual and set that it must Equal = 1
Grab this PBIX file for a working copy
https://1drv.ms/u/s!AtDlC2rep7a-kHP_xOzy4vBRgbEH
Hi @Dz6kb4
Sure. Just create a measure table and don't connect it to anything
The table may contain data like :
I called my table Date Range
ID Value -- -------- 1 This Month 2 Current Month 3 Last Month
Then add that table to a slicer but don't create any relationships between this table and your date table.
Then create a measure on your Date table that uses DAX to determine if your date is part of the grouping.
Date Range Filter = VAR ThisMonth = TODAY() VAR LastMonth = EOMONTH(TODAY(),-1) VAR PrevMonth = EOMONTH(TODAY(),-2) RETURN SWITCH( TRUE() , -- Current Month MAX('Date Range'[ID])=1 && MONTH(MAX('Dates'[Date])) = MONTH(ThisMonth) && YEAR (MAX('Dates'[Date])) = YEAR(ThisMonth) , 1 , -- Last Month MAX('Date Range'[ID])=2 && MONTH(MAX('Dates'[Date])) = MONTH(LastMonth) && YEAR (MAX('Dates'[Date])) = YEAR(LastMonth) , 1 , -- Last Month MAX('Date Range'[ID])=3 && MONTH(MAX('Dates'[Date])) = MONTH(PrevMonth) && YEAR (MAX('Dates'[Date])) = YEAR(PrevMonth) , 1 , -- ELSE 0)
Then just drag this measure in as a filter on your visual and set that it must Equal = 1
Grab this PBIX file for a working copy
https://1drv.ms/u/s!AtDlC2rep7a-kHP_xOzy4vBRgbEH
Hi @Dz6kb4
If you want the current year that's easier.
Date Range Filter = VAR ThisMonth = TODAY() VAR LastMonth = EOMONTH(TODAY(),-1) VAR PrevMonth = EOMONTH(TODAY(),-2) RETURN SWITCH( TRUE() , -- Current Month MAX('Date Range'[ID])=1 && MONTH(MAX('Dates'[Date])) = MONTH(ThisMonth) && YEAR (MAX('Dates'[Date])) = YEAR(ThisMonth) , 1 , -- Last Month MAX('Date Range'[ID])=2 && MONTH(MAX('Dates'[Date])) = MONTH(LastMonth) && YEAR (MAX('Dates'[Date])) = YEAR(LastMonth) , 1 , -- Last Month MAX('Date Range'[ID])=3 && MONTH(MAX('Dates'[Date])) = MONTH(PrevMonth) && YEAR (MAX('Dates'[Date])) = YEAR(PrevMonth) , 1 , -- This year MAX('Date Range'[ID])=4 YEAR (MAX('Dates'[Date])) = YEAR(PrevMonth) , 1 , -- ELSE 0)
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 |
---|---|
111 | |
100 | |
80 | |
64 | |
57 |
User | Count |
---|---|
146 | |
110 | |
93 | |
84 | |
67 |