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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Pishcor
New Member

Weighted data

Dear community,

 

Is there an easy way for me to visualize my wieghted data when using stacked or clustered bars? I have a 'Weigthing variable' in my dataset and I see how I can use this when creating a Pie Chart, but is this also possible for bar charts?

 

Thank you.

 

1 ACCEPTED SOLUTION

You are more than welcome!

And yes, I think I understand what you are trying to accomplish. In this case, you can still use the approach I described earlier to create a weighted score for each food item, but instead of multiplying by the value column, you would multiply by the weighting variable for each moment in the day separately.

 

Here's how you can do it:

 

  1. Create a new calculated column for each moment in the day that you want to analyze (e.g., morning, afternoon, evening) using the same formula as before, but replacing "Value" with the name of the column that contains the frequency of each food item chosen during that moment, and "Weight" with the name of your weighting variable column.

  2. Once you have created the calculated columns for each moment in the day, you can create a stacked or clustered bar chart using the calculated columns as the measures.

  3. To display the scores in percentage, you can divide each calculated column by the total weight for that moment in the day. You can create a new calculated column for each moment in the day that calculates the total weight for that moment by using the following formula:

     

     

    =SUM([Weight])

     

  4. Then, create another calculated column for each moment in the day that calculates the weighted percentage for each food item by dividing the weighted score for that item by the total weight for that moment. You can use the following formula:

     

     

    =DIVIDE([Weighted Score for Food Item], [Total Weight for Moment])

     

  5. Finally, you can use the calculated columns that display the weighted percentages as the measures in your stacked or clustered bar chart. This will show you the percentage of times each food item was chosen during each moment in the day, weighted by your weighting variable.

 

I hope this helps! Let me know if you have any further questions.

 

 

Best regards, 

Isaac Chavarria

If this post helps, then please consider Accept it as the solution and give Kudos to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
ichavarria
Solution Specialist
Solution Specialist

Hi @Pishcor,

 

Yes, it is possible to visualize weighted data using stacked or clustered bars. One approach you can try is to create a calculated field in your dataset that multiplies the value of each data point by its corresponding weight. Then, you can use this calculated field as the measure in your bar chart.

 

Here's how you can create the calculated field:

 

  1. Open your dataset in Power BI.

  2. Click on "Transform data" to open the Power Query Editor.

  3. Add a new column by clicking on "Add Column" in the "Add Column" tab.

  4. In the formula bar, enter the following formula (replace "Value" with the name of your value column and "Weight" with the name of your weight column):

    = [Value] * [Weight]

  5. Press Enter to create the calculated field.

  6. Rename the column to something like "Weighted Value" for clarity.

  7. Click "Close & Apply" to apply the changes to your dataset.

 

Now that you have a calculated field that incorporates the weights, you can use it as the measure in your stacked or clustered bar chart.

 

  1. Click on the "Visualizations" pane on the right side of the screen.

  2. Select "Stacked bar chart" or "Clustered bar chart" from the available visualizations.

  3. Drag your categorical variable to the "Axis" field well and your "Weighted Value" calculated field to the "Values" field well.

  4. If desired, you can add additional fields to the "Legend" and "Tooltip" field wells to further customize your chart.

  5. Adjust any other formatting or settings as needed.

With these steps, you should be able to create a bar chart that incorporates the weighting variable in your dataset. Let me know if you have any questions or if you need further assistance.

 

 

Best regards, 

 

If this post helps, then please consider Accepting it as the solution and giving Kudos to help the other members find it more quickly

Hi Ishavarria,

 

Already a big thanks for your elabarotad answer on my question. I can and will indeed use this for a certain part of my report where I have numeric values. But the real difficultuy lays in the following aspect. I also have non numerical data that I want to weight in Clusterd or Stacked Bars. For example, respondents had to indacate for different moments in a day which type of food items they consumed. So, I want to the scores in % that each product was chosen in the different moments, but weighted by my wieghting variable. I hope that this is clear? 

 

Already a big thanks. 

You are more than welcome!

And yes, I think I understand what you are trying to accomplish. In this case, you can still use the approach I described earlier to create a weighted score for each food item, but instead of multiplying by the value column, you would multiply by the weighting variable for each moment in the day separately.

 

Here's how you can do it:

 

  1. Create a new calculated column for each moment in the day that you want to analyze (e.g., morning, afternoon, evening) using the same formula as before, but replacing "Value" with the name of the column that contains the frequency of each food item chosen during that moment, and "Weight" with the name of your weighting variable column.

  2. Once you have created the calculated columns for each moment in the day, you can create a stacked or clustered bar chart using the calculated columns as the measures.

  3. To display the scores in percentage, you can divide each calculated column by the total weight for that moment in the day. You can create a new calculated column for each moment in the day that calculates the total weight for that moment by using the following formula:

     

     

    =SUM([Weight])

     

  4. Then, create another calculated column for each moment in the day that calculates the weighted percentage for each food item by dividing the weighted score for that item by the total weight for that moment. You can use the following formula:

     

     

    =DIVIDE([Weighted Score for Food Item], [Total Weight for Moment])

     

  5. Finally, you can use the calculated columns that display the weighted percentages as the measures in your stacked or clustered bar chart. This will show you the percentage of times each food item was chosen during each moment in the day, weighted by your weighting variable.

 

I hope this helps! Let me know if you have any further questions.

 

 

Best regards, 

Isaac Chavarria

If this post helps, then please consider Accept it as the solution and give Kudos to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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