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, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
maakef
New Member

Grouping calculated measures

Hello,

 

I am trying to create a calculated measure that takes the sum of a consumer action and divides it by the unique number of consumers in a group, with the ability to track it by week and by action and to filter by a group with the measure automatically updating. I've had a bit of trouble with it so I wanted to see if it's possible.

 

An example of what this measure would look like is as follows:

 

Group 1

A. Week #B. ActionC. Sum of actions by group 1 in week #D. Number of unique group 1 consumers in week #E. Final measure (C/D)
1Kicking1052
1Passing1553
2Coloring1262
2Drawing2464

 

Group 2

A. Week #B. ActionC. Sum of actions by group 2 in week #D. Number of unique group 2 consumers in week #E. Final measure (C/D)
1Kicking1025
1Passing422
2Kicking2045
2Drawing1243
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @maakef ,

I created some data:

vyangliumsft_0-1638262260124.png

Here are the steps you can follow:

1. Create calculated column.

B.Week = WEEKNUM('Group_Table'[Date],2 )

2. Create measure.

Sum of actions by group 1 in week =
CALCULATE(SUM('Group_Table'[amount]),FILTER(ALL(Group_Table),'Group_Table'[Group]=MAX('Group_Table'[Group])&&'Group_Table'[B.Week]=MAX('Group_Table'[B.Week])&&'Group_Table'[Action]=MAX('Group_Table'[Action])))
Number of unique group 1 consumers in week =
CALCULATE(DISTINCTCOUNT('Group_Table'[Date]),
FILTER(ALL('Group_Table'),
'Group_Table'[Group]=MAX('Group_Table'[Group])&&'Group_Table'[Action]=MAX('Group_Table'[Action])))
Final measure (C/D) =
DIVIDE([C. Sum of actions by group 1 in week],[D. Number of unique group 1 consumers in week])

3. Use [group] as the slicer.

4. Result:

When selecting group =1:

vyangliumsft_1-1638262260127.png

When selecting group =2:

vyangliumsft_2-1638262260129.png

 

Best Regards,

Liu Yang

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

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @maakef ,

I created some data:

vyangliumsft_0-1638262260124.png

Here are the steps you can follow:

1. Create calculated column.

B.Week = WEEKNUM('Group_Table'[Date],2 )

2. Create measure.

Sum of actions by group 1 in week =
CALCULATE(SUM('Group_Table'[amount]),FILTER(ALL(Group_Table),'Group_Table'[Group]=MAX('Group_Table'[Group])&&'Group_Table'[B.Week]=MAX('Group_Table'[B.Week])&&'Group_Table'[Action]=MAX('Group_Table'[Action])))
Number of unique group 1 consumers in week =
CALCULATE(DISTINCTCOUNT('Group_Table'[Date]),
FILTER(ALL('Group_Table'),
'Group_Table'[Group]=MAX('Group_Table'[Group])&&'Group_Table'[Action]=MAX('Group_Table'[Action])))
Final measure (C/D) =
DIVIDE([C. Sum of actions by group 1 in week],[D. Number of unique group 1 consumers in week])

3. Use [group] as the slicer.

4. Result:

When selecting group =1:

vyangliumsft_1-1638262260127.png

When selecting group =2:

vyangliumsft_2-1638262260129.png

 

Best Regards,

Liu Yang

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

VahidDM
Super User
Super User

Hi @maakef 

 

Can you post sample data as text and expected output?
Not enough information to go on;

please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
4. Relation between your tables

Appreciate your Kudos!!
LinkedIn:www.linkedin.com/in/vahid-dm/

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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