I have a summary table called, YF_Summary. So while trying to use the built-in median function, the answer was wrong. So i tried to use the manaul formula to calculate median. My requirement is to find the Median of the Unique_Quotes field for last 30 days(this will not change, its 30 always, so median will always be [15throw+16th row]/2. I have applied the filter to the table visual which will select only the last 30 days(exclude today). I used the below query ,
DAX Query:
Median_Quotes =
VAR MinDate = TODAY() - 30
VAR MaxDate = TODAY()
VAR FilteredTable =
FILTER(
ALL('BSDW YF_Summary'),
'BSDW YF_Summary'[Date] >= MinDate &&
'BSDW YF_Summary'[Date] <= MaxDate
)
VAR GroupedTable =
SUMMARIZE(
FilteredTable,
'BSDW YF_Summary'[Date]
)
VAR TotalDays = COUNTROWS(GroupedTable)
VAR MedianRow = DIVIDE(TotalDays, 2)
RETURN
IF(
TotalDays = 0,
BLANK(),
IF(
MOD(TotalDays, 2) = 0,
(
MAXX(
FILTER(GroupedTable, RANKX(GroupedTable, [Unique_Quotes]) = MedianRow),
[Unique Quotes]
) +
MAXX(
FILTER(GroupedTable, RANKX(GroupedTable, [Unique_Quotes]) = MedianRow + 1),
[Unique Quotes]
)
) / 2,
MAXX(
FILTER(GroupedTable, RANKX(GroupedTable, [Unique_Quotes]) = MedianRow + 1),
[Unique Quotes]
)
)
)
The problem is , because of the Rankx functionality, its skipping the 15th, 16th row rank if the consecutive row Unique_Quotes value are same. But irrespective of the value i need to assign rank to the rows. I tried something called Earlier(), skip, and countrows() function too, but it gives balnks as anwer for all rows. Is there anyother way to achieve what i am expecting.
Current Output :

Since there are many values repeating it for the consecutive rows/dates, there is no 15th and 16th rank, so it returns blank as answer.
Your guidance would be of great help.
Thanks in advance.