Power BI Manipulating/Fixing Totals

Power BI Manipulating/Fixing Totals

Recently, lots of people have been talking about fixing the totals in Power BI.

We need to understand how Power BI calculates the total so it will help us manipulate it.

Profit Margin = DIVIDE([Profit],[Revenue],0)        
No alt text provided for this image

For instance, if we use the Dax above to get the profit margin, the total would be calculated in this manner:

(Total Profit) / (Total Revenue)

Hence, profit margin will be for the totals of Profit and the totals of Revenue. If we want to get Average Profit Margin in the total, you can use the following Dax:


Profit Margin Avg =
AVERAGEX(
? ? SUMMARIZE(
? ? ? ? Sales,
? ? ? ? 'Product Category'[Category],
? ? ? ? "PM",[Profit Margin]
? ? ),
? ? [PM]
)        

What summarize does is it creates a table with one column of category and a second column for profit margin (named PM) for each category. Then use this AverageX() to get the average of those Margin values. One thing is to be noted, the average for each category will be the same, only total value will be affected as shown in the matrix visual

No alt text provided for this image

Another problem we can solve with this technique is to eliminate duplicated entries, such as those shown from the data:

No alt text provided for this image

Revenue = SUMX(Sales,Sales[Unit Price]*Sales[Quantity])


Revenue Corrected =
SUMX(
? ? SUMMARIZE(
? ? ? ? Sales,
? ? ? ? Sales[ProductKey],
? ? ? ? "Rev",AVERAGE('Sales'[Unit Price])*AVERAGE(Sales[Quantity])
? ? ),
? ? [Rev]
? ? )         

You may use power query group by to get unique values, but if you have millions of rows with only few duplicate entries, group by will might not be the most effecient approch.

The result will be :

No alt text provided for this image

So what this summarize function is doing here is getting the average for each product key, and since it was duplicate, the average will give a value for one product key. Then SumX() will sum this up for the catergories in rows of the matrix visual.

要查看或添加评论,请登录

Syed Ahmed Ali ???? ????的更多文章

  • Power BI Dynamic Top N (Include Others) using Parameter

    Power BI Dynamic Top N (Include Others) using Parameter

    A few months ago, I worked with a client who had a unique requirement: they needed a filter that could dynamically…

    10 条评论
  • A Comprehensive Guide to Power BI Error Bars

    A Comprehensive Guide to Power BI Error Bars

    Introduction Error bars are essential for visualizing data variability and uncertainty, making them invaluable for more…

    5 条评论
  • Mastering Power BI DAX: IsInScope

    Mastering Power BI DAX: IsInScope

    When working with hierarchies in Power BI, managing totals and granular levels can be challenging. One function that…

    7 条评论
  • Power BI: Highlighting Selected Items

    Power BI: Highlighting Selected Items

    Highlighting specific items in Power BI is a powerful way to enhance data analysis, especially when comparing these…

  • Power BI Dynamic Formatting Trick

    Power BI Dynamic Formatting Trick

    Sharing a cool trick I have been using for dynamic formatting in Power BI which I don't see many people use, and it is…

  • Power BI Custom Label Trick (Dynamic Selection)

    Power BI Custom Label Trick (Dynamic Selection)

    In the realm of data visualization, the utilization of custom labels has unlocked a myriad of possibilities. However, a…

  • Power BI Dynamic Icon Image based on condition (New Card Visual)

    Power BI Dynamic Icon Image based on condition (New Card Visual)

    Did you know you can dynamically show images based on the numerical values with the new card visual. Created this whole…

    7 条评论
  • Distribution Chart Power BI with Gradient Color Using Dax

    Distribution Chart Power BI with Gradient Color Using Dax

    This is simply the combination of Matrix and Scatter plot in Power BI. Problem To create this scatter plot, need…

    2 条评论
  • Power BI Highlighted line based on selection

    Power BI Highlighted line based on selection

    Colors are a powerful tool in visual communication, but too much of a good thing can be overwhelming. This is…

    6 条评论
  • PowerBI Left-Anti Join using DAX(Dynamic)

    PowerBI Left-Anti Join using DAX(Dynamic)

    You can directly use left-anti join in power query, but it won't change with selection on filter. I came across a…

社区洞察

其他会员也浏览了