Question

I am having an issue that I am hoping some more experienced DAX programmers may be able to help me with. I have been trying to develop a dashboard in Excel 2013 / PowerPivot / PowerView and one of the graphics I would like to display is a line chart of median performance by hour of day. I would then like to filter the data set with my performance metrics based on a separate column, and link that to a slicer. The medians should be calculated relative to the filtered data set. For the median calculation I am trying to adapt the formula proposed by Marco Russo here (http://sqlblog.com/blogs/marco_russo/archive/2010/07/20/median-calculation-in-dax.aspx).

To illustrate the problem, suppose that I have two tables - main_table and other_table. Main_table has 4 columns- RowID, hour_of_day, performance_metric, and category. Other_table has two columns- hour_of_day and median_column. My goal is to find a formula for median_column such that it shows the median performance metric by hour of day, but can still be sliced by category. The formula I tried to use for the medians was

=CALCULATE(
    MINX(
        FILTER(
            VALUES(main_table[performance_metric]), 
            CALCULATE(
                COUNTA(main_table[performance_metric]), 
                main_table[performance_metric] <= EARLIER(main_table[performance_metric])) 
                    > COUNTA(main_table[performance_metric]/2),
        main_table[performance_metric]), 
    FILTER(
        main_table, 
        main_table[hour_of_day] = EARLIER(other_table[hour_of_day])))

Or without formatting:

=CALCULATE(MINX(FILTER(VALUES(main_table[performance_metric]), CALCULATE(COUNTA(main_table[performance_metric]), main_table[performance_metric] <= EARLIER(main_table[performance_metric])) > COUNTA(main_table[performance_metric]/2), main_table[performance_metric]), FILTER(main_table, main_table[hour_of_day] = EARLIER(other_table[hour_of_day])))

However, when I create a slicer based on category in main_table, my chart does not seem affected by the slicer. My understanding was that by putting main_table as opposed to ALL(main_table) as the first argument in the last FILTER call, my median calculations would be subject to slices and filters applied to main_table. Am I missing something obvious here?

Was it helpful?

Solution

Calculated columns are apparently computed before queries are executed, therefore anything that needs to be affected by slicers must be entered as a measure, not a calculated column.

Answered in more detail here (http://www.mrexcel.com/forum/powerpivot-questions/741071-medians-context-issues-dax.html#post3641780)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top