Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
NimishBirla
New Member

Help in Date Hierarchy for a Slicer

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?

NimishBirla_0-1736501329482.png

 

 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

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

danextian_0-1736507573307.png

 

 Please see the attached sample pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

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

danextian
Super User
Super User

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

danextian_0-1736507573307.png

 

 Please see the attached sample pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Ritaf1983
Super User
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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors