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

Median of the last 12 months

Hi all, 

 

I was wodering if anyone could help. I need to calcualte the median for the some of the last 12 months of a list of employees. 

 

The meadian formula in PBI, is based in a table column, so i tried to create a virtual table (with sumarise), which returns the table with the last 12 months total, to be used in the median formula, however when i create a real table to check the figures, it returns as blank the column of value. 

 

any idea how can i achive the median of the last 12 months? 

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

As @Greg_Deckler  said ,you could use MEDIANX() function . I just add a Slicer based on it:

Median Value Last 12 Months =
VAR _sele =
    MAX ( ForSlicer[Date] )
VAR _minDate =
    DATE ( YEAR ( _sele ) - 1, MONTH ( _sele ), DAY ( _sele ) )
RETURN
    MEDIANX (
        FILTER (
            EmployeeETable,
            'EmployeeETable'[Date] >= _minDate
                && 'EmployeeETable'[Date] <= _sele
        ),
        [Revenue]
    )

9.7.1.1.PNG

Did I answer your question ? Please mark my reply as solution. Thank you very much.

If not, please upload some insensitive data samples and expected output.

 

Best Regards,

Eyelyn Qin

View solution in original post

5 REPLIES 5
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

As @Greg_Deckler  said ,you could use MEDIANX() function . I just add a Slicer based on it:

Median Value Last 12 Months =
VAR _sele =
    MAX ( ForSlicer[Date] )
VAR _minDate =
    DATE ( YEAR ( _sele ) - 1, MONTH ( _sele ), DAY ( _sele ) )
RETURN
    MEDIANX (
        FILTER (
            EmployeeETable,
            'EmployeeETable'[Date] >= _minDate
                && 'EmployeeETable'[Date] <= _sele
        ),
        [Revenue]
    )

9.7.1.1.PNG

Did I answer your question ? Please mark my reply as solution. Thank you very much.

If not, please upload some insensitive data samples and expected output.

 

Best Regards,

Eyelyn Qin

Anonymous
Not applicable

Thanks @v-eqin-msft  it worked perfectly for my case. 

Greg_Deckler
Super User
Super User

@Anonymous - I'm with @Fowmy , without sample data it's really difficult to know. It might be as simple as:

Median = MEDIANX(FILTER('Table',[Date]>=DATE(YEAR(TODAY()-1),MONTH(TODAY()),DAY(TODAY()))),[Column])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@Anonymous , with a date table, try formula's similar to given in the example

 

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH))
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH))
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Fowmy
Super User
Super User

Hi @Anonymous 

Can you share some sample data and the expected result to have a clear understanding of your question?
You can save your files in OneDrive, Google Drive, or any other cloud sharing platforms and share the link here.
____________________________________
How to paste sample data with your question?
How to get your questions answered quickly?

_____________________________________
Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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