cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
tmhalila
Resolver I
Resolver I

Dynamic filter last four quarters regardless the year

Hello everyone,

Please assist. I want to present a chart that will auto-filter the last four quarters regardless of the year e.g., FY21 Q4, FY22 Q1, FY22 Q2, and FY22 Q3. I have attached the sample file below. NOTE: Quarter One starts on October

 

Screenshot 2023-07-07 135658.png

 

Here is the file: Power BI File 

2 ACCEPTED SOLUTIONS
Nithinr
Resolver I
Resolver I

Create a measure that returns quarter difference with your max date in fact table.

use below measure in the visual filters to display number of quarters you want. quarter.png

 

QuartersDiff = var maximum = CALCULATE(MAX(testing[boardapprovaldate]),ALL('testing'))
RETURN
DATEDIFF(MAX(testing[boardapprovaldate]),maximum,QUARTER)

 

View solution in original post

danextian
Super User
Super User

Hi @tmhalila 

 

When you say last four quarters, is that based on the latest quarter in testing table or based on a slicer selection? If it is based on the slicer selection, you must use a disconnected dates table - one which doesn't have relationship to dates or testing table. Otherwise, your visual show just whatever is selected from the slicer.

First, sort your quarters first by ranking

Quarter Sort = 
RANKX (
    VALUES ( 'dim date'[fiscalquarter&year] ),
    'dim date'[fiscalquarter&year],
    ,
    ASC,
    Dense
)

Create a disconnected table (more than one ways to do it but you can reference your dates table)

dim date (disconnected) = 
'dim date'

Create a measure that will show just the last four quarters based on slicer selection

Count new =
VAR currentquartersort =
    SELECTEDVALUE ( 'dim date (disconnected)'[Quarter Sort] )
RETURN
    CALCULATE (
        [No of Project],
        FILTER (
            'dim date',
            'dim date'[Quarter Sort] >= currentquartersort - 3
                && 'dim date'[Quarter Sort] <= currentquartersort
        )
    )

Replace the column used in quarter slicer with the one from the disconnected dates table.

danextian_0-1688738092060.png

 

Please see attached pbix for details.

 






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."
Connect to me on LinkedIn || Need consulting? Hire me for a Power BI gig on UpWork.
Learn with me on YouTube @PowerBITambayan.

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @tmhalila 

 

When you say last four quarters, is that based on the latest quarter in testing table or based on a slicer selection? If it is based on the slicer selection, you must use a disconnected dates table - one which doesn't have relationship to dates or testing table. Otherwise, your visual show just whatever is selected from the slicer.

First, sort your quarters first by ranking

Quarter Sort = 
RANKX (
    VALUES ( 'dim date'[fiscalquarter&year] ),
    'dim date'[fiscalquarter&year],
    ,
    ASC,
    Dense
)

Create a disconnected table (more than one ways to do it but you can reference your dates table)

dim date (disconnected) = 
'dim date'

Create a measure that will show just the last four quarters based on slicer selection

Count new =
VAR currentquartersort =
    SELECTEDVALUE ( 'dim date (disconnected)'[Quarter Sort] )
RETURN
    CALCULATE (
        [No of Project],
        FILTER (
            'dim date',
            'dim date'[Quarter Sort] >= currentquartersort - 3
                && 'dim date'[Quarter Sort] <= currentquartersort
        )
    )

Replace the column used in quarter slicer with the one from the disconnected dates table.

danextian_0-1688738092060.png

 

Please see attached pbix for details.

 






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."
Connect to me on LinkedIn || Need consulting? Hire me for a Power BI gig on UpWork.
Learn with me on YouTube @PowerBITambayan.

This is something incredible, I didn't think of it, but I see this is the best way to handle selection on the slicer. It adds more flexibility with multiple visuals.

Nithinr
Resolver I
Resolver I

Create a measure that returns quarter difference with your max date in fact table.

use below measure in the visual filters to display number of quarters you want. quarter.png

 

QuartersDiff = var maximum = CALCULATE(MAX(testing[boardapprovaldate]),ALL('testing'))
RETURN
DATEDIFF(MAX(testing[boardapprovaldate]),maximum,QUARTER)

 

Thanks for the response! This is short and clear.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors