Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
The current output of my measure is the total count across all months. I want to adjust my measure so that the output is the Median of the total for each month.
Current Output:
Output = 229
Desired Output:
July: 56
August: 56
September: 60
October: 57
Median = 56.5
My measure is exluding November and December, so sometimes the median will be across 4 months, sometimes 5 months, and sometimes 6 months, depending on the time of year.
Hi @TJK
Can you try this dax:
Median Monthly Count =
VAR StartDate = EDATE(TODAY(), -7) -- 7 months back from today
VAR TodayDate = TODAY()
VAR CurrentTime = TIME(HOUR(UTCNOW()) - 5, MINUTE(UTCNOW()), SECOND(UTCNOW()))
VAR ThresholdTime = TIME(12, 30, 0)
-- Create a table with distinct count per month
VAR MonthlyCounts =
ADDCOLUMNS(
SUMMARIZE(
'Opportunity',
'Opportunity'[LOI Date].[Year],
'Opportunity'[LOI Date].[Month]
),
"@Count",
CALCULATE(
DISTINCTCOUNT('Opportunity'[Id]),
'Opportunity'[LOI Date] >= StartDate &&
'Opportunity'[LOI Date] <= TodayDate &&
NOT (MONTH('Opportunity'[LOI Date]) IN {11, 12}), -- Exclude Nov and Dec
IF(
CurrentTime > ThresholdTime,
'Opportunity'[Days Until EOM] < SELECTEDVALUE('LOI Date'[Days Until EOM Sort]),
'Opportunity'[Days Until EOM] <= SELECTEDVALUE('LOI Date'[Days Until EOM Sort])
),
MONTH('Opportunity'[LOI Date]) = MONTH('Opportunity'[Close Date]),
YEAR('Opportunity'[LOI Date]) = YEAR('Opportunity'[Close Date])
)
)
-- Compute the median from the monthly totals
RETURN MEDIANX(MonthlyCounts, [@Count])
Hi @Poojara_D12
Your measure did not give me the expected outcome. Here's a sample pbix file that describes what I expect the outcome to be.
@TJK So something like:
Measure 4 =
MEDIANX(
ADDCOLUMNS( DISTINCT( 'Dates'[Month] ), "__Value", [Measure 3] ),
[__Value]
)
Hi @Greg_Deckler the measure you provided is giving me the total across all months (same output as my original measure 3)
Hi @TJK
Thanks for the reply from Greg_Deckler .
TJK , the following test is for your reference.
Sample:
Measure:
Median =
VAR _table =
SUMMARIZE ( 'Table', 'Table'[Month], "Monthly", SUM ( 'Table'[Value] ) )
RETURN
MEDIANX ( _table, [Monthly] )
Output:
Best Regards,
Yulia Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @v-xuxinyi-msft
I do not have a table with the values for each month. I want to perform the median using my "Measure 3"
Hi @TJK
It seems that two tables are used in your Measure3, could you please provide some sample data about these two tables so that we can help you better. How to provide sample data in the Power BI Forum - Microsoft Fabric Community Please remove any sensitive data in advance.
Best Regards,
Yulia Xu
Hi @v-xuxinyi-msft
Here is a link to the sample data. Thank you for your help.
https://www.dropbox.com/scl/fi/m0qwug2lz7w4m6a8n8duf/Count-of-Records-After-Selected-Date.pbix?rlkey...
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
23 | |
12 | |
10 | |
9 | |
8 |
User | Count |
---|---|
16 | |
15 | |
15 | |
12 | |
10 |