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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
charithaa
New Member

How to Calculate Average categorie wise based on Consecutive days

charithaa_0-1730705960200.png

I need to get Average of Avg Actual Efficiency considering Effective Date's Consecutive days by Plant Code Wise, PRODUCT_TYPE, CHASSIS_CODE wise, SUB CHASSIS wise, Work_center wise, Style Wise. Excluding sunday. Same style can be run different time range. so I need to that consecutive days average.Exmple: In Plant A051, style U2662 is runnig in Work Center UP01, days are 01/01/2024,02/01/2024,03/03/2024,04/05/2024 this days has actual effi 20,30,24,50. need to get average of runnig days. if days discrete don't get to calculate the average. we should consider calandar dates only.

 

3 REPLIES 3
v-tianyich-msft
Community Support
Community Support

Hi @charithaa ,

 

Has your problem been solved? If not, please share the sample file so we can help you better.

 

Best regards,
Community Support Team_ Scott Chang

FarhanJeelani
Solution Supplier
Solution Supplier

To calculate the average efficiency based on consecutive days, excluding Sundays, and grouped by the specified columns in Power BI, follow these steps. This solution requires DAX formulas to handle the grouping and averaging for only consecutive calendar days.

 

Step 1: Import and Prepare Data
1. Import your data into Power BI.
2. Ensure the Effective Date column is formatted as a date data type.

 

Step 2: Add a Column to Determine Consecutive Days
1. Create an Index Column to track row numbers. This will help in identifying consecutive days.
- Go to Transform Data > Add Column > Index Column > From 1.

 

2. Create a Calculated Column for Consecutive Days Check:
Use the following DAX formula to identify if each row is a consecutive day (excluding Sundays) from the previous row, based on Plant Code, PRODUCT_TYPE, CHASSIS_CODE, SUB CHASSIS, Work_Center, and Style:

DAX

 

IsConsecutive =
IF(
TableName[Plant Code] = EARLIER(TableName[Plant Code]) &&
TableName[PRODUCT_TYPE] = EARLIER(TableName[PRODUCT_TYPE]) &&
TableName[CHASSIS_CODE] = EARLIER(TableName[CHASSIS_CODE]) &&
TableName[SUB CHASSIS] = EARLIER(TableName[SUB CHASSIS]) &&
TableName[Work_Center] = EARLIER(TableName[Work_Center]) &&
TableName[Style] = EARLIER(TableName[Style]) &&
WEEKDAY(TableName[Effective Date], 2) <> 7 &&
DATEDIFF(EARLIER(TableName[Effective Date]), TableName[Effective Date], DAY) = 1,
1,
0
)

 



Replace `TableName` with your actual table name. This column (`IsConsecutive`) will have a value of `1` if the day is consecutive (excluding Sundays) and `0` otherwise.

 

 Step 3: Group Data by Consecutive Blocks
1. Create a Calculated Column for Grouping Consecutive Blocks:
Create another calculated column to assign a unique identifier to each block of consecutive days.

DAX

 

ConsecutiveGroup =
SUMX(
FILTER(
TableName,
TableName[Index] <= EARLIER(TableName[Index]) &&
TableName[IsConsecutive] = 1
),
1
)

 

This column (`ConsecutiveGroup`) will assign a unique number to each group of consecutive days for each combination of `Plant Code`, `PRODUCT_TYPE`, `CHASSIS_CODE`, `SUB CHASSIS`, `Work_Center`, and `Style`.

 

Step 4: Calculate the Average Efficiency for Consecutive Days
1. Create a Measure for Average Efficiency:
Use the following DAX measure to calculate the average `Avg Actual Efficiency` for each group of consecutive days.

DAX

 

AvgEfficiencyConsecutive =
CALCULATE(
AVERAGE(TableName[Avg Actual Efficiency]),
ALLEXCEPT(
TableName,
TableName[Plant Code],
TableName[PRODUCT_TYPE],
TableName[CHASSIS_CODE],
TableName[SUB CHASSIS],
TableName[Work_Center],
TableName[Style],
TableName[ConsecutiveGroup]
)
)

 



This measure will calculate the average efficiency only for consecutive days within each combination of the specified categories.

Step 5: Visualize the Results
1. Use a Table or Matrix Visual in Power BI to display the data.


2. Add Plant Code, PRODUCT_TYPE, CHASSIS_CODE, SUB CHASSIS, Work_Center, Style, and ConsecutiveGroup as rows, and use the `AvgEfficiencyConsecutive` measure as values.


3. This will show the average efficiency for each consecutive run of days for each unique combination of fields, excluding Sundays.

 

This setup will ensure that only consecutive calendar days are considered for the efficiency average, and any gaps (non-consecutive days) will separate the calculation into different groups. Let me know if you need further customization!

 

Hi @charithaa 

 

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

 

Thanks,

Farhan

Hi @charithaa ,

 

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

 

Thanks,

Farhan

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.