Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext 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
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_NUMBER | ORDER_GROUP_ID | SKID_COUNT | SHIP_DATE |
| 801676 | 21 | 1/1/2022 | |
| 801762 | 3 | 1/1/2022 | |
| 801772 | 21 | 1/1/2022 | |
| 801782 | 4 | 1/1/2022 | |
| 801836 | 2 | 1/1/2022 | |
| 801697 | 801697 | 4 | 1/1/2022 |
| 801736 | 801697 | 5 | 1/1/2022 |
| 801780 | 801697 | 5 | 1/1/2022 |
| 801787 | 801787 | 4 | 2/2/2022 |
| 801799 | 801787 | 4 | 2/2/2022 |
| 801815 | 801787 | 2 | 2/2/2022 |
Solved! Go to Solution.
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 )
Pat
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 )
Pat
Thank you Pat, this works!
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 48 | |
| 45 | |
| 41 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 69 | |
| 63 | |
| 32 | |
| 31 | |
| 25 |