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, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
mramstead1
Frequent Visitor

Lookup / Unique Count Problem in DAX

Example Excel File with Data 

 

Hello!

 

I need help with the above file. I am trying to write a function within PowerPivot that will lookup 'Activity Code' from [Activity Info] and put the corresponding value 'Minutes to Complete' for each activity code. The end goal with this is to build a Pivot Table that will multiply the count of each activity code with the minutes it takes to complete that activity. This will be scaled up for each employee (this part of the model is working) so that I am able to measure workload.

 

I'm not entirely sure how the Pivot Table interacts with PowerPivot, so I would love any solution that results in a Pivot Table column containing the product of minutes spent on an activity with the count of said activity.

 

Thank you in advance!

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hello @mramstead1 !

 

For this sort of calculation, I would suggest writing a measure that:

  1. Groups the 'Activity Report' table by ActivityInfo[Minutes to Complete]
  2. Iterates over this grouped table, multiplying ActivityInfo[Minutes to Complete] by the row count of 'Activity Report'.

To do this, I would create two measures:

 

Activity Count =
COUNTROWS ( 'Activity Report' )
Total Minutes =
SUMX (
    SUMMARIZE( 'Activity Report', ActivityInfo[Minutes to Complete] ),
    ActivityInfo[Minutes to Complete]
        * [Activity Count]
)

 

 

You can then create a PivotTable with 'ActivityInfo'[Activity Code] on the rows, with the Total Minutes measure displayed.

 

This measure should work correctly with any other filters you might want to apply.

 

I've knocked this together in a copy of your Excel file, with a 2nd PivotTable displaying the two measures (attached).

OwenAuger_0-1642572042316.png

 

Is that the sort of thing you were looking for?

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hello @mramstead1 !

 

For this sort of calculation, I would suggest writing a measure that:

  1. Groups the 'Activity Report' table by ActivityInfo[Minutes to Complete]
  2. Iterates over this grouped table, multiplying ActivityInfo[Minutes to Complete] by the row count of 'Activity Report'.

To do this, I would create two measures:

 

Activity Count =
COUNTROWS ( 'Activity Report' )
Total Minutes =
SUMX (
    SUMMARIZE( 'Activity Report', ActivityInfo[Minutes to Complete] ),
    ActivityInfo[Minutes to Complete]
        * [Activity Count]
)

 

 

You can then create a PivotTable with 'ActivityInfo'[Activity Code] on the rows, with the Total Minutes measure displayed.

 

This measure should work correctly with any other filters you might want to apply.

 

I've knocked this together in a copy of your Excel file, with a 2nd PivotTable displaying the two measures (attached).

OwenAuger_0-1642572042316.png

 

Is that the sort of thing you were looking for?

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

@OwenAuger you beauty! This worked splendidly, I greatly appreciate your time and help!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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