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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
slatka11
Helper I
Helper I

Conditional average by month

I am looking to write a DAX to calculate the average skid count by month but the average should take the sum of the skids in an order group if there is one. Below is the sample data. 

 

For example, the February average should calculate as 10 in the sample data because there is a group, and January should calculate as 10.83 ((21+3+21+4+2+14)/6). 

 

ORDER_NUMBERORDER_GROUP_IDSKID_COUNTSHIP_DATE
801676 211/1/2022
801762 31/1/2022
801772 211/1/2022
801782 41/1/2022
801836 21/1/2022
80169780169741/1/2022
80173680169751/1/2022
80178080169751/1/2022
80178780178742/2/2022
80179980178742/2/2022
80181580178722/2/2022
1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

Here's a measure expression that shows one way to do it.

 

Avg Skid_Count =
//var NoGroupSum = CALCULATE(SUM(T6[SKID_COUNT]), ISBLANK(T6[ORDER_GROUP_ID]))
VAR NoGroupCount =
    CALCULATE ( COUNT ( T6[SKID_COUNT] ), ISBLANK ( T6[ORDER_GROUP_ID] ) )
VAR OrderGroupCount =
    DISTINCTCOUNTNOBLANK ( T6[ORDER_GROUP_ID] )
VAR TotalSkidCount =
    SUM ( T6[SKID_COUNT] )
RETURN
    DIVIDE ( TotalSkidCount, NoGroupCount + OrderGroupCount )

 

ppm1_0-1674393935902.png

 

Pat

Microsoft Employee

View solution in original post

2 REPLIES 2
ppm1
Solution Sage
Solution Sage

Here's a measure expression that shows one way to do it.

 

Avg Skid_Count =
//var NoGroupSum = CALCULATE(SUM(T6[SKID_COUNT]), ISBLANK(T6[ORDER_GROUP_ID]))
VAR NoGroupCount =
    CALCULATE ( COUNT ( T6[SKID_COUNT] ), ISBLANK ( T6[ORDER_GROUP_ID] ) )
VAR OrderGroupCount =
    DISTINCTCOUNTNOBLANK ( T6[ORDER_GROUP_ID] )
VAR TotalSkidCount =
    SUM ( T6[SKID_COUNT] )
RETURN
    DIVIDE ( TotalSkidCount, NoGroupCount + OrderGroupCount )

 

ppm1_0-1674393935902.png

 

Pat

Microsoft Employee

Thank you Pat, this works!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.