Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
In a slicer, I have added a date hierarchy of year and month. A user can select a whole year as well as a specific month of any year, but when a user selects a whole year instead of a specific month for that year, i want default to be a month selected for that year instead of the whole year to be selected.
Is there a way to achieve this?
Solved! Go to Solution.
Hi @NimishBirla
If you will be showing a visual without the dates, you can just create a measure. However, if you want to show the dates as well, then you will need a disconnected table (without relationship to your fact and dimension tables) as using a related dimension will filter the dates to what is within the range so if your default month is outside the range, your visual will return blank.
The sample measure below is to be used as a visual filter.
DateFilter with Default =
// Define the default month for filtering
VAR DefaultMonth = "Jun"
// Create a filtered table of disconnected dates for the default month
VAR FilteredDisconnectedDates =
SUMMARIZE (
FILTER ( DisconnectedDate, DisconnectedDate[Month Short] = DefaultMonth ),
[Date]
)
// Calculate the number of rows in the Dates table based on the filter context
RETURN
IF (
// Check if there is a single value for DisconnectedDate[Month Short] in the filter context
NOT ( HASONEVALUE ( DisconnectedDate[Month Short] ) ),
// Calculate the number of rows where Dates[Date] is in the filtered disconnected dates
CALCULATE (
COUNTROWS ( Dates ),
KEEPFILTERS ( TREATAS ( FilteredDisconnectedDates, Dates[Date] ) )
),
// Calculate the number of rows where Dates[Date] matches the values in DisconnectedDate[Date]
CALCULATE (
COUNTROWS ( Dates ),
KEEPFILTERS ( TREATAS ( VALUES ( DisconnectedDate[Date] ), Dates[Date] ) )
)
)
Please see the attached sample pbix.
Proud to be a Super User!
Hi @NimishBirla ,
Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.
If these also don't help, please share more detailed information and description to help us clarify your scenario to test.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng
Hi @NimishBirla
If you will be showing a visual without the dates, you can just create a measure. However, if you want to show the dates as well, then you will need a disconnected table (without relationship to your fact and dimension tables) as using a related dimension will filter the dates to what is within the range so if your default month is outside the range, your visual will return blank.
The sample measure below is to be used as a visual filter.
DateFilter with Default =
// Define the default month for filtering
VAR DefaultMonth = "Jun"
// Create a filtered table of disconnected dates for the default month
VAR FilteredDisconnectedDates =
SUMMARIZE (
FILTER ( DisconnectedDate, DisconnectedDate[Month Short] = DefaultMonth ),
[Date]
)
// Calculate the number of rows in the Dates table based on the filter context
RETURN
IF (
// Check if there is a single value for DisconnectedDate[Month Short] in the filter context
NOT ( HASONEVALUE ( DisconnectedDate[Month Short] ) ),
// Calculate the number of rows where Dates[Date] is in the filtered disconnected dates
CALCULATE (
COUNTROWS ( Dates ),
KEEPFILTERS ( TREATAS ( FilteredDisconnectedDates, Dates[Date] ) )
),
// Calculate the number of rows where Dates[Date] matches the values in DisconnectedDate[Date]
CALCULATE (
COUNTROWS ( Dates ),
KEEPFILTERS ( TREATAS ( VALUES ( DisconnectedDate[Date] ), Dates[Date] ) )
)
)
Please see the attached sample pbix.
Proud to be a Super User!
Hi @NimishBirla
You can use a similar method as in the linked video:
https://www.youtube.com/watch?v=JlVHsZUk1nc
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
User | Count |
---|---|
126 | |
78 | |
78 | |
60 | |
51 |
User | Count |
---|---|
164 | |
84 | |
68 | |
68 | |
58 |