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

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.

Reply
Anonymous
Not applicable

slicer to split data in half

I have a single table source.  This table has a Date attribute.  This Date spans a 6-month range.  I have created a derived column in my PBI data model to identify if the given date is in the first half of the time range or the second half of the time range (i.e., 'first 3 months', 'last 3 months').  The user is now asking for the ability to select the entire time range vs just the first 3 months, as a slicer with single-select (so, something like 'first 3 months', 'all 6 months').  How can I achieve this?

3 REPLIES 3
danextian
Super User
Super User

Hi @Anonymous,

 

Without a sample data, I can only imagine how it looks. 

There are many ways to achieve your requirement and this just one.

  • Create this calculated column in your table which will return the month order starting from the earliest date. 
Rolling Month Number =
DATEDIFF (
    CALCULATE ( MIN ( 'Table'[Date] ), ALL ( 'Table' ) ),
    'Table'[Date],
    MONTH
) + 1
  • Create this calculated table. This should be a disconnected table and should not have a relationship with your fact table.
  • Range =
    DATATABLE (
        "Range", STRING,
        "MaxMonth", INTEGER,
        {
            { "first 3 months", 3 },
            { "all six months", 6 }
        }
    )
    ​

     

  • Use this measure to as a visual filter.  From the filters pane, select is not blank. 

  • RowCount = 
    CALCULATE (
        COUNTROWS ( 'Table' ), 
        FILTER ( 'Table', 'Table'[Rolling Month Number] <= MAX ( Range[MaxMonth] ) )
    )
  • Use the Range column from the calculated table Range in a slicer. If "first 3 months" is selected, the RowCount measure will return blank for rolling month numbers 4-6 and will not be visible in your visual. If not a single item is selected, the above measure will not filter any rows. If you don't want to show any data if no item is selected, you may change <= MAX ( Range[MaxMonth] ) ) to <= SELECTEDVALUE ( Range[MaxMonth] ) ).









  • 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.
    Anonymous
    Not applicable

    It would be helpful if you could provide sample pbix file.

    Anonymous
    Not applicable

    @AnonymousHow can I post a sample pbix file?  I don't see an option in this forum to attach files.

    Helpful resources

    Announcements
    Microsoft Fabric Learn Together

    Microsoft Fabric Learn Together

    Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

    PBI_APRIL_CAROUSEL1

    Power BI Monthly Update - April 2024

    Check out the April 2024 Power BI update to learn about new features.

    April Fabric Community Update

    Fabric Community Update - April 2024

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