Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
Hi,
I am creating the equivalent of the SQL Query in POWER BI
SQL QUERY:
ROUND(MEDIAN(CASE WHEN CHALLENGERESULT = 'ABC' AND PRIORPRICE <> 0 AND CREATEDTIMESTAMP BETWEEN TRUNC(TO_DATE('26-JAN-2019','DD-MON-YYYY'))-8
AND TRUNC(TO_DATE('26-JAN-2019','DD-MON-YYYY')) THEN ((ABS(POSTPRICE-PRIORPRICE))/PRIORPRICE)*100 ELSE NULL END),2) "W % Adjustment Magnitude"
DAX:
Solved! Go to Solution.
hi @Anonymous
MEDIAN
MEDIAN(<column>)
https://docs.microsoft.com/en-us/dax/median-function-dax
MEDIANX
MEDIANX(<table>, <expression>)
https://docs.microsoft.com/en-us/dax/medianx-function-dax
Since in your DAX formula, blue part is expression, so you need MEDIANX instead of MEDIAN
ROUND(MEDIAN(CALCULATE(COUNTROWS(TABLE),FILTER(TABLE,TABLE[CHALLENGERESULT] = "ABC" && TABLE[PRIORPRICE]<> 0 && TABLE[CREATEDTIMESTAMP].[Date] >= ( SELECTEDVALUE('DATE TABLE'[Date] ) - W_NO_DAYS ) && TABLE[CREATEDTIMESTAMP].[Date] < (SELECTEDVALUE('DATE TABLE'[Date]) - W_NO_DAYS ) + W_NO_DAYS ))),2)
https://blog.enterprisedna.co/how-to-calculate-the-median-value-in-power-bi-using-dax/
Regards,
Lin
Calculate already return summed up rows, another function might not work
Use medianx
https://docs.microsoft.com/en-us/dax/medianx-function-dax
Take out formula till calculating into a variable
medianx_1 =
Var _formula = <You formula till calculate >
return
medianx(table,_formula )
But you need to have some level in between
medianx_1 =
Var _formula = <You formula till calculate >
return
medianx(values(table[Level of countrows]),_formula )
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601
hi @Anonymous
MEDIAN
MEDIAN(<column>)
https://docs.microsoft.com/en-us/dax/median-function-dax
MEDIANX
MEDIANX(<table>, <expression>)
https://docs.microsoft.com/en-us/dax/medianx-function-dax
Since in your DAX formula, blue part is expression, so you need MEDIANX instead of MEDIAN
ROUND(MEDIAN(CALCULATE(COUNTROWS(TABLE),FILTER(TABLE,TABLE[CHALLENGERESULT] = "ABC" && TABLE[PRIORPRICE]<> 0 && TABLE[CREATEDTIMESTAMP].[Date] >= ( SELECTEDVALUE('DATE TABLE'[Date] ) - W_NO_DAYS ) && TABLE[CREATEDTIMESTAMP].[Date] < (SELECTEDVALUE('DATE TABLE'[Date]) - W_NO_DAYS ) + W_NO_DAYS ))),2)
https://blog.enterprisedna.co/how-to-calculate-the-median-value-in-power-bi-using-dax/
Regards,
Lin
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.