Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Compare individual value with median

Hi everyone,

 

I believe I will need a push in the right direction to calculate, compare and summarize the output of several generators per time period.

 

Raw Data

DateProjectDevice NoOutput
25-SepSydney12310
25-SepSydney22400
25-SepSydney32430
25-SepSydney42390
25-SepSydney52420
25-SepSydney62380
25-SepBrisbane11860
25-SepBrisbane21890
25-SepBrisbane31730
25-SepBrisbane41830
26-SepSydney12100
26-SepSydney22110
26-SepSydney32080
26-SepSydney42090
26-SepSydney52100
26-SepSydney62120
26-SepBrisbane11600
26-SepBrisbane21610
26-SepBrisbane31680
26-SepBrisbane41660

 

Step 1

For each time period (in this example day) I want to compare the output of each generator with the median of all generators at that location.

If the individual output is above the median, I deem that generator as fully available (=1). If below, it is deemed as not available (=0).

 

DateProjectDevice NoOutputMedian per project per dayAbove Median
25-SepSydney1231023950
25-SepSydney2240023951
25-SepSydney3243023951
25-SepSydney4239023950
25-SepSydney5242023951
25-SepSydney6238023950
25-SepBrisbane1186018451
25-SepBrisbane2189018451
25-SepBrisbane3173018450
25-SepBrisbane4183018450
26-SepSydney1210021001
26-SepSydney2211021001
26-SepSydney3208021000
26-SepSydney4209021000
26-SepSydney5210021001
26-SepSydney6212021001
26-SepBrisbane1160016350
26-SepBrisbane2161016350
26-SepBrisbane3168016351
26-SepBrisbane4166016351

 

Step 2

Now I need to sum up these numbers.

 

ProjectDevice NoSum of Above Median
Sydney11
Sydney22
Sydney31
Sydney40
Sydney52
Sydney61
Brisbane11
Brisbane21
Brisbane31
Brisbane41

 

 

In PowerBI I have calculated the median as follwoing: 

MedianPerProjectPerDay = CALCULATE(median(Output[Output]),ALL(Output[DeviceNo]))
 
And compare the individual with the following measure:
Sumx = sumx(Output,if(Output[Output]>[MedianPerProjectPerDay],1,0))
 

Somehow my sumx measure median does not work across several rows.

 

 

 

Excel file with final result: https://www.dropbox.com/s/ru33h3wr2vkr6g5/CompareWMedian.xlsx?dl=0

 

PBIX with my approach: https://www.dropbox.com/s/qy1e4jm5ikc9byj/CompareWMedian.pbix?dl=0

 

 

 

Many thanks upfront.

Regards

Andreas

2 ACCEPTED SOLUTIONS
stevedep
Memorable Member
Memorable Member

Hi there @Anonymous ,

 

This is what I have for you:

__ComparewithMedian = 
SUMX(SUMMARIZE('Table','Table'[Date],'Table'[Device No], "c",
IF(SUM('Table'[Output]) > 
CALCULATE(MEDIANX('Table', 'Table'[Output]), ALLEXCEPT('Table','Table'[Project], 'Table'[Date])), 1, 0)),[c])

As seen here:

media.pngLink to file

Please mark as solution if so. Thumbs up for the effort are appreciated.

Kind regards, 
Steve.  

View solution in original post

Anonymous
Not applicable

Awesome, Thanks @stevedep . Much appreciate your help.

View solution in original post

4 REPLIES 4
stevedep
Memorable Member
Memorable Member

Hi there @Anonymous ,

 

This is what I have for you:

__ComparewithMedian = 
SUMX(SUMMARIZE('Table','Table'[Date],'Table'[Device No], "c",
IF(SUM('Table'[Output]) > 
CALCULATE(MEDIANX('Table', 'Table'[Output]), ALLEXCEPT('Table','Table'[Project], 'Table'[Date])), 1, 0)),[c])

As seen here:

media.pngLink to file

Please mark as solution if so. Thumbs up for the effort are appreciated.

Kind regards, 
Steve.  

Anonymous
Not applicable

Awesome, Thanks @stevedep . Much appreciate your help.

amitchandak
Super User
Super User

@Anonymous , You need values on some group by to make it work

 

Sumx = sumx(values(Output[project]) ,if(Sum(Output[Output])>[MedianPerProjectPerDay],1,0))

 

or create median as column not measure

Anonymous
Not applicable

Thanks @amitchandak ,

I tried this and a few other ideas, but am still stuck. Your provided measeure sums up the output and then compares it with the median. Therefore I will always only get 1 as maximum. I need to compare the individual output value with the median for that period, determine if it is 0 or 1 and then sum up all the 1s.

 

I also tried to do it via calculated column as 

CalColMedian = CALCULATE(MEDIAN(Output[Output]),ALL(Output[DeviceNo]))

Which gives me te following error message: "Expressions that yield variant data-type cannot be used to define calculated columns."

 

Just to double check, I used AVERAGE, which seems to produce a result. But it seems the calculation is limited to the values within a row

CalColMedian = CALCULATE(AVERAGE(Output[Output]),ALL(Output[DeviceNo]))
 
 
Next I tried to create a calculated table with the aim to use lookupvalue later.
CalTabSummarize = SUMMARIZE(Output,Output[Project],Output[Date].[Date],"MedianDayProject_tab",MEDIAN(Output[Output]))
Which gives me the following error: "The DAX expression for calculated table 'CalTabSummarize' results in a variant data type for column 'MedianDayProject_tab'. Please modify the calculation such that the column has a consistent data type."
 
Replacing it with Average works again
CalTabSummarize = SUMMARIZE(Output,Output[Project],Output[Date].[Date],"MedianDayProject_tab",AVERAGE(Output[Output]))
 
After a lot of trying I am still lost...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors