cancel
Showing results 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

Helper I

## Calculating variance from multiple columns from the same table

Hi Team,

I have the below input and want to calculate variance based on the description column. also want the output to be in table or matrix form.

Input:

 id description symptoms conduct_problem hyperactivity problem prosocial impact score 150 Start 4 7 10 8 6 4 15 150 End 3 5 8 4 7 7 7 160 Start 7 3 5 7 4 10 18 160 Start 5 5 5 6 2 8 16 160 End 5 5 5 6 2 6 13 160 End 5 4 4 9 2 8 18 164 Start 7 2 2 5 6 10 19 164 End 5 4 2 5 8 7 14 173 Start 9 7 10 7 4 4 10 173 End 8 7 9 7 2 9 8 188 Start 7 3 7 0 9 6 9 188 End 7 3 5 0 6 5 16 189 Start 6 8 10 5 7 4 12 189 End 4 6 9 4 7 2 11

Expected output:

 Scale Start End diff symptoms 6.43 5.29 1.14 conduct_problem 5.00 4.86 0.14 hyperactivity 7.00 6.00 1.00 problem 5.43 5.00 0.43 prosocial 5.43 4.86 0.57 impact 6.57 6.29 0.29 score 14.14 12.43 1.71 all Total 50.00 44.71 5.29

Please not that the value of Start and End is the average value based on id column. and the all Total is the summantion of the 7 rows.

Is this possible in power bi?

3 ACCEPTED SOLUTIONS
Super User

@P_P2595 , Unpivot the all column other than Id and description , then you can have measures like

M1 = calculate(Average(Table[Value]), filter(Table, Table[Description] ="Start") )

M2= calculate(Average(Table[Value]), filter(Table, Table[Description] ="End") )

Diff = [M1] -[M2]

Learn Power BI: Power Query UnPivot Data, Pivot Data, Transpose Data, Query Fill Up, Fill Down: https://www.youtube.com/watch?v=cN8AO3_vmlY&t=36407s

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
https://1drv.ms/u/s!AiUZ0Ws7G26RiGy6Yf6quAn_ATjG?e=zsB0R6

Super User

Hi,

Please find attached my solution file.

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
4 REPLIES 4
Helper I

Hi all,
Thanks for your solutions and it’s working for me. Is it possible to get the same output without unpivoting the columns as I have some pages and visuals with that table and extra columns than the input data and I don't want to unpivot the data because it's affecting other pages and visuals.
Is there any other way to get the expected output by creating a measure and calculated column?
Thank you so much.

Super User

Hi,

Please find attached my solution file.

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
https://1drv.ms/u/s!AiUZ0Ws7G26RiGy6Yf6quAn_ATjG?e=zsB0R6

Super User

@P_P2595 , Unpivot the all column other than Id and description , then you can have measures like

M1 = calculate(Average(Table[Value]), filter(Table, Table[Description] ="Start") )

M2= calculate(Average(Table[Value]), filter(Table, Table[Description] ="End") )

Diff = [M1] -[M2]

Learn Power BI: Power Query UnPivot Data, Pivot Data, Transpose Data, Query Fill Up, Fill Down: https://www.youtube.com/watch?v=cN8AO3_vmlY&t=36407s

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

Announcements

#### 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 Monthly Update - June 2024

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

#### New forum boards available in Real-Time Intelligence.

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

Top Solution Authors
Top Kudoed Authors