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
lea_313
Helper I
Helper I

Count based on multiple criteria

Hiya

 

I need to calculate some counts but its proving a bit tricky

 

Sample data below

 

Project code IDProduct forMonthYearRevenueProduct HeaderStage
1544Class 1January20221000Event10% booked
1544Class 1February20221000Event100% delivered
1533Class 1January20222500Face to face10% booked
1354Class 5March20221450Session10% booked
1544Class 1May20221000Event100% delivered
1566Class 6December20221500Session10% booked
1533Class 1February20221500Face to face100% delivered
1533Class 1April20221000Face to face10% booked
1544Class 1April20221000Event100% delivered

 

Project code is a code used to group sales together

 

I need to be able to count, for each unique project code, is it active? and if it is, how many product headers are active by summing the codes?

 

The break down the steps:

  - For project code 1544, there is 4 lines to consider

  - If any of these lines have a stage of less than 100% delivered, then the project is still active

  - If the project is still active, then the is a count of 1 for the product header 'event'

  - This needs to consider year, but I should be able to add this as a filter to the page/table etc

 

So the output I want to see from the table above is as follows

 

Product HeaderYearCount of active projects
Event20221
Face to face20221
Session20221

 

You'll see there are origninally 4 project codes, but the output only shows 3. This is becasue project code 1566 is fully delivered an no longer active

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@lea_313 , so you actually do want to count up the number of [Project code ID] that are active? Then I think this measure will work:

Active Project Count = 
    SUMX(
        VALUES('lea_313'[Project code ID])
        ,MAXX('lea_313', IF(FIND("100%", 'lea_313'[Stage], 1, 0) = 0, 1, 0))
    )

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

@lea_313 , I believe this measure will give you the desired results:

Has Active Project = 
    MAXX(
        'YourTable'
        , VAR vStagePercentPosition = FIND("%", 'YourTable'[Stage], 1, 0) -1
        VAR vStagePercent = VALUE(LEFT('YourTable'[Stage], vStagePercentPosition))
        RETURN
            IF(vStagePercent < 100, "Y", "N")
    )

I get the following:

Feedback Type:
(Error)

MdxScript(Model) (47, 29) Calculation error in measure [Active Project]: Cannot convert value 'G. 100' of type Text to type Number.

 

My actual stage is anything that is not G.100% Delivered

 

Thanks

 

 

 

Anonymous
Not applicable

@lea_313 , in the sample data you provided you did not mention that the Stage column can contain values such as "G. 100%". Try this alternative measure:

Has Active Project = 
    MAXX(
        'YourTable'
        , VAR vStagePercentPosition = FIND("100%", 'YourTable'[Stage], 1, 0) 
        RETURN
            IF(vStagePercentPosition = 0, "Y", "N")
    )

 

Hiya

 

Thanks for your help

 

lea_313_0-1656924992152.png

I've added the measure. I get a Y/N rather than a count of active projects by project code. How do I convert this to a count please?

 

For example, there are 10 active Coaching, 5 active team in 2022

 

Thanks

Anonymous
Not applicable

@lea_313 , so you actually do want to count up the number of [Project code ID] that are active? Then I think this measure will work:

Active Project Count = 
    SUMX(
        VALUES('lea_313'[Project code ID])
        ,MAXX('lea_313', IF(FIND("100%", 'lea_313'[Stage], 1, 0) = 0, 1, 0))
    )

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.