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

The 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.

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.










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


Proud to be a Super User!









"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
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
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.










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


Proud to be a Super User!









"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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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