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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
POSPOS
Post Patron
Post Patron

How to show the count for last 5 years and median for last 8 quarters

Hi,

I have a requirement to show the count for last 5 years and median for last 8 quarters  based on submission date.

One column chart with - 5 years of count and median

POSPOS_0-1722637505754.png

Second column chart by last 8 Quarters 

POSPOS_1-1722637540436.png

 

There is a page level filter where activation data is not blank.
If there is no data for the current year then , it should should still show 5 years and 8 quarters based on the submission date.
Eg: If there is no data for current year, 1st chart should show data from 2023 to 2019.

Sample pbix available here
can someone please suggest on how to achieve this?

3 REPLIES 3
v-nuoc-msft
Community Support
Community Support

Hi @POSPOS 

 

Thank you very much S7728 and lbendlin for your prompt reply.

 

For your question, here is the method I provided:

 

You need a date table to use as a year in the slicer.

 

Create a new table. And create a slicer.

 

Table = 
CALENDAR(
    DATE(YEAR(TODAY()), 1, 1), 
    TODAY()
)

 

vnuocmsft_0-1724047461856.png

vnuocmsft_3-1724047734862.png

 

Create measures.

 

count1 = 
var _year = SELECTEDVALUE('Table'[Date].[Year])
RETURN 
    CALCULATE(
        DISTINCTCOUNT(data[Protocol Number]),
        FILTER(
            'data',
            'data'[Year] >= _year - 5
            &&
            NOT(ISBLANK('data'[Activation Date])
            
        )
    )
)

 

median1 = 
var _year = SELECTEDVALUE('Table'[Date].[Year])
RETURN
CALCULATE(
    MEDIAN(data[datediff]),
    FILTER(
        'data',
        'data'[Year] >= _year - 5
    )
)

 

You can view Page 1 and page 2.

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

S7728
Frequent Visitor

Count for the Last 5 Years:

CountLast5Years =
CALCULATE(
COUNT('Table'[SubmissionDate]),
FILTER(
'Table',
'Table'[SubmissionDate] >= DATE(YEAR(TODAY()) - 5, 1, 1)
)
)

Median for the Last 8 Quarters:

MedianLast8Quarters =
CALCULATE(
MEDIAN('Table'[SubmissionDate]),
FILTER(
'Table',
'Table'[SubmissionDate] >= EDATE(TODAY(), -24)
)
)

 

lbendlin
Super User
Super User

lbendlin_0-1722690942844.png

Not really clear what you need but here's a proposal.

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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