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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
CBurton87
Frequent Visitor

# of occurrences based on measure calculations

Hi all, I am trying to group sales people in to three groups. 

 

Green = Above budget

Amber = >85% of budget

Red = <85% of budget

 

I have a single table that holds actual and budget figures at a customer level, each customer line has the sales owner.

 

to start with, i have some basic measures.

 

Actuals $ = CALCULATE(sum('Sales Table'[USD_Amount]),filter('Sales Table','Sales Table'[Type]="Actual"))

Budget $ = CALCULATE(sum('Sales Table'[USD_Amount]),filter('Sales Table','Sales Table'[Type]="Budget"))

 

I then have a measure to calculate the budget % achieved

 

Budget % = divide([Actuals $],[Budget $],blank())

 

from this, i need to count, how many sales people are Green, Amber and Red based on the above logic.

 

any help would be appreciated.

 

Thanks.

1 ACCEPTED SOLUTION

So, this is the disconnected table trick. In general, to use a measure in that way, you need to use the Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...

 

In your case, creat this table, I call this Table19:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkpNUYrViVZyL0pNzQOzHHOTUouUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Code = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}})
in
    #"Changed Type"

Create the Measure that I specified, I called this measure "Code".

 

Create this measure:

 

Count of Code = 
VAR __code = MAX('Table19'[Code])
VAR __tmpTable = SUMMARIZE('Table18',[Sales Owner],"__code",[Code])
RETURN COUNTROWS(FILTER(__tmpTable,[__code]=__code))

Put Code from Table19 into the Axis and Count of Code as the Value in a bar/column chart. Table18 is my Sales table.

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Measure = IF([Budget %] > 1,"Green",IF([Budget %]<.85,"Red","Amber"))

?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks Greg, 

 

that would allow me to show in table visualisation who is Red, Amber and Green,

 

but in addition to that, i need to know how many are Red, how many are Amber and how many are Green.

sort of a distinct count of sales peoples names based on Red, Amber and Green.

 

thanks and

Best Regards,

You can use SUMMARIZE, ADDCOLUMNS and such for that. Sample data and expected output would be really helpful. 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


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Here is a basic version of the data that should hopefully help.

 

Sales Table

 

TypeAccountKeyMonthYearUSD AmountSales Owner
ActualM03624956712018716Person 1
ActualM0363511011201892Person 2
BudgetM03624956712018785Person 1
BudgetM03635110112018407Person 2
ActualM03624956722018930Person 1
ActualM036351101220189Person 2
BudgetM03624956722018507Person 1
BudgetM03635110122018692Person 2
ActualM03624956732018956Person 1
ActualM03635110132018742Person 2
BudgetM0362495673201877Person 1
BudgetM03635110132018902Person 2
ActualM03624955512018945Person 3
ActualM03635158912018752Person 4
BudgetM03624955512018836Person 3
BudgetM03635158912018492Person 4
ActualM03624955522018862Person 3
ActualM0363515892201813Person 4
BudgetM03624955522018983Person 3
BudgetM03635158922018673Person 4
ActualM03624955532018874Person 3
ActualM03635158932018299Person 4
BudgetM03624955532018879Person 3
BudgetM036351589320189Person 4

 

the visualisations on the report allow the user to cut the data by month and year.

 

thanks and

Best Regards,

 

So, this is the disconnected table trick. In general, to use a measure in that way, you need to use the Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...

 

In your case, creat this table, I call this Table19:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkpNUYrViVZyL0pNzQOzHHOTUouUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Code = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}})
in
    #"Changed Type"

Create the Measure that I specified, I called this measure "Code".

 

Create this measure:

 

Count of Code = 
VAR __code = MAX('Table19'[Code])
VAR __tmpTable = SUMMARIZE('Table18',[Sales Owner],"__code",[Code])
RETURN COUNTROWS(FILTER(__tmpTable,[__code]=__code))

Put Code from Table19 into the Axis and Count of Code as the Value in a bar/column chart. Table18 is my Sales table.

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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