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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
VizDataLtd
Helper I
Helper I

Accessing data with Stdev and Variance aggregation in place

Hello,

 

The user is able to select an aggregation type in the frontend by clicking the down arrow on a number series (e.g. Sum, Min, Max, Count). I have identified that which method they pick is stored within expr.func (I hope this helps someone; it took me a while to find it). I built the following mapping to let me apply the correct calculation based on expr.func. But it won't work for stdev or variance. After some hunting, I realise that when Stdev or Variance is selected by the user, the values passed into options.dataViews[0].categorical.values[numberIndex].values are all zeroes (e.g. [0,0,0,0]). I would expect this if the numbers are identical, but they are not.

To put it another way, the following log
console.log(options.dataViews[0].categorical.values[numberIndex].values); outputs [3000, 2000, 1000, 5000] if I have Sum selected, but [0,0,0,0] if I have Stdev selected. Is Stdev/variance not supported for custom visuals or is there some kind of rounding issue going on - and if so how do i fix it please?

 

 

export const AGGREGATION_METHODS = {
    0: { name: 'sum', calculate: (values: number[]) => values.reduce((a, b) => a + b, 0) },
    1: { name: 'avg', calculate: (values: number[]) => values.reduce((a, b) => a + b, 0) / values.length },
    2: { name: 'count distinct', calculate: (values: number[]) => new Set(values).size },
    3: { name: 'min', calculate: (values: number[]) => Math.min(...values) },
    4: { name: 'max', calculate: (values: number[]) => Math.max(...values) },
    5: { name: 'count', calculate: (values: number[]) => values.length },
    6: { name: 'median', calculate: (values: number[]) => {
            const sorted = values.slice().sort((a, b) => a - b);
            const mid = Math.floor(sorted.length / 2);
            return sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
        }
    },
    7: { name: 'stdev', calculate: (values: number[]) => {
            const mean = values.reduce((sum, v) => sum + v, 0) / values.length;
            const variance = values.reduce((sum, v) => sum + Math.pow(v - mean, 2), 0) / (values.length - 1);
            return Math.sqrt(variance);
        }
    },
    8: { name: 'variance', calculate: (values: number[]) => {
            const mean = values.reduce((a, b) => a + b, 0) / values.length;
            return values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / values.length;
        }
    },
};

 

 

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @VizDataLtd ,

May I confirm if your question pertains to Power BI? If so, could you kindly provide some data or screenshots to help me better understand the problem? Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.