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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Jraj2380
New Member

Need Sum & Avg in different conditions

Find the below data and i need to Sum the Value when (i)Emp_Name same, (ii) Start/End Dates are Same and (iii) Project Codes are different. And then, Aeverage the value for the given month. Please help me to write a Dax for this output. Thank you.

 

Emp_NamePROJECT CODEStart DateEnd DateALLOCATION %UTILIZATION
RameshABCD01/10/202431/10/2024100%Yes
SureshEFGH01/10/202431/10/2024100%No
KiranIJKL01/10/202414/10/2024100%Yes
KiranMNOP15/10/202431/10/202450%No
KiranMNOP15/10/202431/10/202450%Yes

 

Need below outputs:

 

Avg Allocation100%
Avg Utilization - Yes83%
Avg Utilization - No75%
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Jraj2380 

Please try the following measure:

Avg Allocation = 
VAR _name = SELECTEDVALUE('Table'[Emp_Name])
VAR _startdate = SELECTEDVALUE('Table'[Start Date])
VAR _enddate = SELECTEDVALUE('Table'[End Date])
RETURN
SUMX(FILTER(ALL('Table'),'Table'[Emp_Name] = _name && 'Table'[Start Date] = _startdate && 'Table'[End Date] = _enddate),'Table'[ALLOCATION %])

 

Avg Utilization - Yes = 
VAR _name = SELECTEDVALUE('Table'[Emp_Name])
VAR _startdate = SELECTEDVALUE('Table'[Start Date])
VAR _enddate = SELECTEDVALUE('Table'[End Date])
RETURN
SUMX(FILTER(ALL('Table'),'Table'[UTILIZATION] = "Yes" && 'Table'[Emp_Name] = _name && 'Table'[Start Date] = _startdate && 'Table'[End Date] = _enddate),'Table'[ALLOCATION %])

 

Avg Utilization - No = 
VAR _name = SELECTEDVALUE('Table'[Emp_Name])
VAR _startdate = SELECTEDVALUE('Table'[Start Date])
VAR _enddate = SELECTEDVALUE('Table'[End Date])
RETURN
SUMX(FILTER(ALL('Table'),'Table'[UTILIZATION] = "No" && 'Table'[Emp_Name] = _name && 'Table'[Start Date] = _startdate && 'Table'[End Date] = _enddate),'Table'[ALLOCATION %])


Result:

vjialongymsft_0-1732003552050.png

 

 

 

 

 

 

Best Regards,

Jayleny

 

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

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Jraj2380 

Please try the following measure:

Avg Allocation = 
VAR _name = SELECTEDVALUE('Table'[Emp_Name])
VAR _startdate = SELECTEDVALUE('Table'[Start Date])
VAR _enddate = SELECTEDVALUE('Table'[End Date])
RETURN
SUMX(FILTER(ALL('Table'),'Table'[Emp_Name] = _name && 'Table'[Start Date] = _startdate && 'Table'[End Date] = _enddate),'Table'[ALLOCATION %])

 

Avg Utilization - Yes = 
VAR _name = SELECTEDVALUE('Table'[Emp_Name])
VAR _startdate = SELECTEDVALUE('Table'[Start Date])
VAR _enddate = SELECTEDVALUE('Table'[End Date])
RETURN
SUMX(FILTER(ALL('Table'),'Table'[UTILIZATION] = "Yes" && 'Table'[Emp_Name] = _name && 'Table'[Start Date] = _startdate && 'Table'[End Date] = _enddate),'Table'[ALLOCATION %])

 

Avg Utilization - No = 
VAR _name = SELECTEDVALUE('Table'[Emp_Name])
VAR _startdate = SELECTEDVALUE('Table'[Start Date])
VAR _enddate = SELECTEDVALUE('Table'[End Date])
RETURN
SUMX(FILTER(ALL('Table'),'Table'[UTILIZATION] = "No" && 'Table'[Emp_Name] = _name && 'Table'[Start Date] = _startdate && 'Table'[End Date] = _enddate),'Table'[ALLOCATION %])


Result:

vjialongymsft_0-1732003552050.png

 

 

 

 

 

 

Best Regards,

Jayleny

 

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

 

Kedar_Pande
Super User
Super User

@Jraj2380 

Create measures:

Total Allocation =
SUMX(
FILTER(
'Table',
EARLIER('Table'[Emp_Name]) = 'Table'[Emp_Name] &&
EARLIER('Table'[Start Date]) = 'Table'[Start Date] &&
EARLIER('Table'[End Date]) = 'Table'[End Date] &&
EARLIER('Table'[PROJECT CODE]) <> 'Table'[PROJECT CODE]
),
'Table'[ALLOCATION %]
)
Avg Allocation =
AVERAGEX(
SUMMARIZE(
'Table',
'Table'[Emp_Name],
'Table'[Start Date],
'Table'[End Date],
"TotalAllocation", [Total Allocation]
),
[TotalAllocation]
)
Avg Utilization Yes =
AVERAGEX(
FILTER(
'Table',
'Table'[UTILIZATION] = "Yes"
),
'Table'[ALLOCATION %]
)
Avg Utilization No =
AVERAGEX(
FILTER(
'Table',
'Table'[UTILIZATION] = "No"
),
'Table'[ALLOCATION %]
)

The outputs will be displayed in a card visual or table, depending on your preference:

Avg Allocation: From [Avg Allocation]
Avg Utilization - Yes: From [Avg Utilization Yes]
Avg Utilization - No: From [Avg Utilization No]

 

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

Poojara_D12
Super User
Super User

Hi @Jraj2380 

To calculate the required outputs, follow these steps to write a DAX measure. We'll break down the logic step-by-step.


1. Group and Sum Allocation

We first need to group the data based on these conditions:

  • Emp_Name is the same.
  • Start Date and End Date are the same.
  • Project Code is different.

For this, use SUMMARIZE to create a temporary table that aggregates the data based on your criteria.


DAX Measures

Step 1: Grouped Allocation

Create a measure to calculate the total allocation based on your grouping logic.

 

Grouped Allocation = 
SUMX(
    SUMMARIZE(
        TableName,
        TableName[Emp_Name],
        TableName[Start Date],
        TableName[End Date],
        TableName[UTILIZATION], // Include UTILIZATION for filtering later
        "Sum Allocation", SUMX(
            DISTINCT(TableName[PROJECT CODE]),
            VALUE(LEFT(TableName[ALLOCATION %], LEN(TableName[ALLOCATION %]) - 1))
        )
    ),
    [Sum Allocation]
)

 

Step 2: Average Allocation

Calculate the average allocation for the given month.

 

Avg Allocation = 
DIVIDE(
    [Grouped Allocation], 
    DISTINCTCOUNT(TableName[Emp_Name])
)

 

Step 3: Average Utilization for "Yes"

Filter the grouped data for utilization marked as "Yes" and calculate the average.

 

Avg Utilization - Yes = 
DIVIDE(
    SUMX(
        FILTER(
            SUMMARIZE(
                TableName,
                TableName[Emp_Name],
                TableName[Start Date],
                TableName[End Date],
                TableName[UTILIZATION],
                "Sum Allocation", SUMX(
                    DISTINCT(TableName[PROJECT CODE]),
                    VALUE(LEFT(TableName[ALLOCATION %], LEN(TableName[ALLOCATION %]) - 1))
                )
            ),
            TableName[UTILIZATION] = "Yes"
        ),
        [Sum Allocation]
    ),
    DISTINCTCOUNT(
        FILTER(TableName, TableName[UTILIZATION] = "Yes")[Emp_Name]
    )
)

 

 

To calculate the required outputs, follow these steps to write a DAX measure. We'll break down the logic step-by-step.


1. Group and Sum Allocation

We first need to group the data based on these conditions:

  • Emp_Name is the same.
  • Start Date and End Date are the same.
  • Project Code is different.

For this, use SUMMARIZE to create a temporary table that aggregates the data based on your criteria.


DAX Measures

Step 1: Grouped Allocation

Create a measure to calculate the total allocation based on your grouping logic.

DAX
Copy code
Grouped Allocation = SUMX( SUMMARIZE( TableName, TableName[Emp_Name], TableName[Start Date], TableName[End Date], TableName[UTILIZATION], // Include UTILIZATION for filtering later "Sum Allocation", SUMX( DISTINCT(TableName[PROJECT CODE]), VALUE(LEFT(TableName[ALLOCATION %], LEN(TableName[ALLOCATION %]) - 1)) ) ), [Sum Allocation] )

Step 2: Average Allocation

Calculate the average allocation for the given month.

DAX
Copy code
Avg Allocation = DIVIDE( [Grouped Allocation], DISTINCTCOUNT(TableName[Emp_Name]) )

Step 3: Average Utilization for "Yes"

Filter the grouped data for utilization marked as "Yes" and calculate the average.

DAX
Copy code
Avg Utilization - Yes = DIVIDE( SUMX( FILTER( SUMMARIZE( TableName, TableName[Emp_Name], TableName[Start Date], TableName[End Date], TableName[UTILIZATION], "Sum Allocation", SUMX( DISTINCT(TableName[PROJECT CODE]), VALUE(LEFT(TableName[ALLOCATION %], LEN(TableName[ALLOCATION %]) - 1)) ) ), TableName[UTILIZATION] = "Yes" ), [Sum Allocation] ), DISTINCTCOUNT( FILTER(TableName, TableName[UTILIZATION] = "Yes")[Emp_Name] ) )

Step 4: Average Utilization for "No"

Similarly, calculate the average for utilization marked as "No".

 

Avg Utilization - No = 
DIVIDE(
    SUMX(
        FILTER(
            SUMMARIZE(
                TableName,
                TableName[Emp_Name],
                TableName[Start Date],
                TableName[End Date],
                TableName[UTILIZATION],
                "Sum Allocation", SUMX(
                    DISTINCT(TableName[PROJECT CODE]),
                    VALUE(LEFT(TableName[ALLOCATION %], LEN(TableName[ALLOCATION %]) - 1))
                )
            ),
            TableName[UTILIZATION] = "No"
        ),
        [Sum Allocation]
    ),
    DISTINCTCOUNT(
        FILTER(TableName, TableName[UTILIZATION] = "No")[Emp_Name]
    )
)

 

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
YouTube: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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