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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
niculeica
Helper I
Helper I

COUNT measure assistance

Hi!

 

I'm having some troubles trying to COUNT the number of projects, split per 3 criteria (Margin% is <0%, between 0% and 20%, then >20%). So I've created a separate table called MarginIntervals, which has a column with the 3 margin types, then there's another table, Timeline.

 

So, Margin% as a standalone measure works perfectly, it's calculated as (Revenue-Cost)/Revenue, and is relative to each month in Timeline table. The formula is pretty standard, a measure with declared variables (Month&Year from Timeline table as VAR Time, to be equal to Month&Year from Projects table).

 

Now, would you calculate MarginCount measure based on Margin% (from Projects table) and MarginTypes (from MarginIntervals table)? It feels like measure based on measure pretty much gets stuck...

 

So the formula is kinda like:

 

MarginCount =
VAR MarginTypes =
MAX(_Margins[MarginTypes])
RETURN
IF(MarginTypes="<0%",CALCULATE(COUNTA(Projects[Project: ID]),FILTER(Projects,[Margin%]<0),
IF(MarginTypes="0% - 20%",CALCULATE(COUNTA(Projects[Project: ID]),FILTER(Projects,[Margin%]>=0&&[Margin%]<=20%,
CALCULATE(COUNTA(Projects[Project: ID]),FILTER(Projects,[Margin%]>20%)))
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @niculeica ,

 

Based on your description I created simple test data.

 

MarginIntervals:

vlinhuizhmsft_0-1729216069698.png

Projects:

vlinhuizhmsft_1-1729216118295.png

Timeline:

vlinhuizhmsft_2-1729216165855.png

You can use the SWITCH function and create a slicer to accomplish your needs. Please follow the steps:

 

1.Create the relationship:

vlinhuizhmsft_3-1729216216522.png

 

2.Create a new column:

Margin% = DIVIDE('Projects'[Revenue]-'Projects'[Cost],'Projects'[Revenue])

vlinhuizhmsft_4-1729216345064.png

 

3.Create a measure:

MarginCount = 
SWITCH(
    SELECTEDVALUE(MarginIntervals[MarginTypes]),
    "<0%",CALCULATE(COUNTA('Projects'[ProjectID]),FILTER(Projects, 'Projects'[Margin%] < 0)),
    "0% - 20%",CALCULATE(COUNTA('Projects'[ProjectID]),FILTER(Projects, 'Projects'[Margin%] >= 0 && 'Projects'[Margin%] <= 0.2)),
    ">20%",CALCULATE(COUNTA(Projects[ProjectID]),FILTER(Projects, 'Projects'[Margin%] > 0.2)),
    BLANK()
)

 

4.The result is as follows:

vlinhuizhmsft_5-1729216508381.png

vlinhuizhmsft_6-1729216530861.png

 

Best Regards,
Zhu
Community Support Team

 

If there is any 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
Ashish_Mathur
Super User
Super User

Hi,

Share some data to work with and show the expected result.  Share data in a format that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @niculeica ,

 

Based on your description I created simple test data.

 

MarginIntervals:

vlinhuizhmsft_0-1729216069698.png

Projects:

vlinhuizhmsft_1-1729216118295.png

Timeline:

vlinhuizhmsft_2-1729216165855.png

You can use the SWITCH function and create a slicer to accomplish your needs. Please follow the steps:

 

1.Create the relationship:

vlinhuizhmsft_3-1729216216522.png

 

2.Create a new column:

Margin% = DIVIDE('Projects'[Revenue]-'Projects'[Cost],'Projects'[Revenue])

vlinhuizhmsft_4-1729216345064.png

 

3.Create a measure:

MarginCount = 
SWITCH(
    SELECTEDVALUE(MarginIntervals[MarginTypes]),
    "<0%",CALCULATE(COUNTA('Projects'[ProjectID]),FILTER(Projects, 'Projects'[Margin%] < 0)),
    "0% - 20%",CALCULATE(COUNTA('Projects'[ProjectID]),FILTER(Projects, 'Projects'[Margin%] >= 0 && 'Projects'[Margin%] <= 0.2)),
    ">20%",CALCULATE(COUNTA(Projects[ProjectID]),FILTER(Projects, 'Projects'[Margin%] > 0.2)),
    BLANK()
)

 

4.The result is as follows:

vlinhuizhmsft_5-1729216508381.png

vlinhuizhmsft_6-1729216530861.png

 

Best Regards,
Zhu
Community Support Team

 

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

 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.