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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
wasirafi
Helper I
Helper I

DAX expression - How to calculate Weightage average based on a condition

Hello Community,

 

I have been scratching my head for many hours to get a DAX for the following Data table

 

SKUDateTotal TimeReasonAvailabilityPerformance
Apple12-12-2334Break50%65%
Apple12-12-2322Reduced speed45%83%
Banana12-12-2342Reduced speed36%87%
Carrot12-12-2354Break37%46%
Apple13-12-2320Reduced speed65%44%
Banana13-12-2322Reduced speed12%39%
Banana13-12-2355Break35%44%
Carrot13-12-2311Break43%77%
Carrot13-12-2345Break29%61%
Apple14-12-2311Break34%37%
Apple14-12-2325Break80%63%
Banana14-12-2345Break33%35%
Carrot14-12-2339Break26%64%
Apple15-12-2320Break75%72%
Banana15-12-2333Break23%56%
Banana15-12-2335Reduced speed34%78%
Carrot15-12-2323Break23%38%
Carrot15-12-2370Break26%66%

 

I am trying to get weighted average (Availability) and Weighted Average (Performance) based on SKU or Date ( what ever i set as a filter). The result should only include "Break" as a Reason.

 

Ultimately i am trying to achieve the below Values (i dont need a table)

Weightage is Total time for the filter/ total time. For example 34/90=38%,11/90=12%

1) Filter at SKU Level

 Reason Filter : Break only     
    Availability Performance
Apple   61.9% 62.6%

2) Filter at Date

 Reason Filter : Break only     
Date   Availability Performance
12-12-23   42.0% 53.3%
13-12-23   33.1% 54.5%

https://1drv.ms/x/s!AjIGh95acxebg6F7lBBXTOoz7qe0rw?e=AIlOND 

1 ACCEPTED SOLUTION

9 REPLIES 9
wasirafi
Helper I
Helper I

Super Guru's @amitchandak @Ahmedx @lbendlin  Please help

lbendlin_0-1703729455035.png

 

@lbendlin 

Can you pelase support here again....

Using the DAX your shared i end with many NaN ....how do fix this...

FYI i am using the divide functionNaN error.PNG

Wt.OEE.PNG

https://1drv.ms/u/s!AjIGh95acxebg6tTfM75XKf7YlPPXw?e=3j9j3p 

https://1drv.ms/x/s!AjIGh95acxebg6tU03koymicjRCeXQ?e=q9kFzD 

 

You cannot measure a measure directly. Either materialize it first, or create a separate measure that implements the entire business logic.

 

 

You provided way too much data.  Cut the problem down to the essentials and fix that first.

@lbendlin ,

Dax is a weakness for me. What would u suggest the new Dax should be that captures the solution i want ( as shared in the excel). We dont aggregate at "location name" alone -its a straight value. Any aggregation above location name wether its Area name or site name etc should be weighted average( based on the total time for oee2 = sum of upseconds+downseconds)

 

I intentionally provided more data ( more rows of data) to ensure the NaN issues for all rows is sorted.

The NaN is caused by your attempt to measure measures. Use SUMMARIZE to materialize the measures, and then SUMX. 

 

Please explain the weighting logic again.

You are a Genius!!!!🙂

123abc
Community Champion
Community Champion

To calculate the weighted average of Availability and Performance based on a condition (in this case, "Break") using DAX in Power BI, you can follow these steps:

  1. Create a Measure for Total Time for 'Break' Reason:

TotalTime_Break =
SUMX(
FILTER(
YourTableName,
YourTableName[Reason] = "Break"
),
YourTableName[Total Time]
)

 

Calculate the Weighted Average for 'Break' Reason:

For the Availability and Performance weighted average, use the following measures:

 

WeightedAvg_Availability = 
DIVIDE(
    CALCULATE(
        SUMX(
            FILTER(
                YourTableName, 
                YourTableName[Reason] = "Break"
            ), 
            YourTableName[Total Time] * YourTableName[Availability]
        ),
        ALL(YourTableName)
    ),
    [TotalTime_Break]
)
 
WeightedAvg_Performance = 
DIVIDE(
    CALCULATE(
        SUMX(
            FILTER(
                YourTableName, 
                YourTableName[Reason] = "Break"
            ), 
            YourTableName[Total Time] * YourTableName[Performance]
        ),
        ALL(YourTableName)
    ),
    [TotalTime_Break]
)

 

 

  1. Using the Measures in Visuals:

    • If you want to see the weighted averages for each SKU with the 'Break' reason:

      • Drag and drop the SKU into a table or matrix visualization.
      • Drag the WeightedAvg_Availability and WeightedAvg_Performance measures into the values section of the visualization.
    • If you want to see the weighted averages for each Date with the 'Break' reason:

      • Similarly, drag and drop the Date into a table or matrix visualization.
      • Again, drag the WeightedAvg_Availability and WeightedAvg_Performance measures into the values section.

Remember to replace YourTableName with the actual name of your table in Power BI.

These DAX measures should give you the desired weighted averages based on the 'Break' reason either at the SKU level or Date level as per your filters in Power BI.

@123abc  Thank you for sharing this, Unfortunately i am not getting the desired result Please See Pic from Power BI Versus what was expected( manual calculation in the excel sheet shared earlier). The sum of the weighted average cannot be more than 100% .desired result.PNGpowerbi snap.PNG 

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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