Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi Guys, I have this measure:
CalcuateData =
var calcType = SELECTEDVALUE('Calculate By'[ComputeBy])
RETURN
SWITCH(
TRUE(),
calcType = "Average", AVERAGEX(VALUES(car[ExtractedDate].[Date]), CALCULATE(SUM(car[Cnt]))),
MEDIANX(VALUES(car[ExtractedDate].[Date]),CALCULATE(SUM(car[Cnt])))
)
For the average, I got the result:
but for the median:
I only have two months. It seems like the month should be finished before having the value for median, is there a way to have the median regardless if the month is not finished?
Please see sample raw data:
| Team | Type | ExtractedDate | Cnt |
| Team Red | Sedan | 02/09/2021 | 3 |
| Team Red | Sedan | 03/09/2021 | 3 |
| Team Red | Sedan | 09/09/2021 | 3 |
| Team Red | Sedan | 27/08/2021 | 4 |
| Team Red | Hatchback | 08/09/2021 | 4 |
| Team Red | Hatchback | 09/09/2021 | 5 |
| Team Red | Hatchback | 05/11/2021 | 1 |
| Team Blue | Hatchback | 27/08/2021 | 1 |
| Team Blue | Hatchback | 30/08/2021 | 1 |
| Team Blue | Hatchback | 31/08/2021 | 2 |
| Team Blue | Sedan | 17/11/2021 | 4 |
| Team Blue | Sedan | 18/11/2021 | 4 |
| Team Blue | Sedan | 19/11/2021 | 4 |
| Team Blue | Hatchback | 27/10/2021 | 1 |
| Team Yellow | Hatchback | 09/09/2021 | 6 |
| Team Yellow | Hatchback | 10/09/2021 | 5 |
| Team Yellow | Hatchback | 13/09/2021 | 4 |
| Team Yellow | Sedan | 14/09/2021 | 3 |
Any tips? Thank you in advance
Solved! Go to Solution.
@Anonymous , Try with minor changes
CalcuateData =
var calcType = Max('Calculate By'[ComputeBy])
RETURN
SWITCH(
TRUE(),
calcType = "Average", AVERAGEX(VALUES(car[ExtractedDate]), CALCULATE(SUM(car[Cnt]))),
MEDIANX(VALUES(car[ExtractedDate]),CALCULATE(SUM(car[Cnt])))
)
@Anonymous , Try with minor changes
CalcuateData =
var calcType = Max('Calculate By'[ComputeBy])
RETURN
SWITCH(
TRUE(),
calcType = "Average", AVERAGEX(VALUES(car[ExtractedDate]), CALCULATE(SUM(car[Cnt]))),
MEDIANX(VALUES(car[ExtractedDate]),CALCULATE(SUM(car[Cnt])))
)
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 41 | |
| 38 | |
| 36 | |
| 30 | |
| 28 |
| User | Count |
|---|---|
| 128 | |
| 88 | |
| 79 | |
| 67 | |
| 62 |