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
Mal_Sondh
Helper II
Helper II

Creating charts using Pivot data and CountA and CountIF from Excel

Hi All,

 

I have the following data (Project Table):

Project NoProject NameProject DescriptionIT OwnerBusiness OwnerProject StageCountryDivisionProject Start DateProject Completion Date% CompleteMissed ChanceBusiness EfficiencyDemandRiskImproved QualityCommunicationKnowledgeResponsiveExpertiseValue
1AAAJKRSInitialUKProduct01/12/201914/10/2020 LateY YY32354
2BBBJKRSIn ProgressFinlandProduct01/01/202014/12/20200%Late YYY43345
3CCCJKTTIn ProgressChinaProduct01/12/201914/12/202030% Y YY54354
4DDDJKTTIn ProgressUKProduct01/12/201914/10/202025%  YYY52344
5EEETZRSIn ProgressBelgiumInfra01/12/201914/10/202065%LateY   42454
6FFFTZEBIn ProgressItalyProduct01/12/201814/10/202086%Late Y  42544
7GGGTZEBIn ProgressUKWealth01/12/201914/10/202092% Y   42252
8HHHTZEBIn ProgressUKInfra01/12/201914/10/202010%  Y Y4 145
9IIITZSMIn ProgressUKInfra01/12/201914/10/202027%LateY  Y5 15 
10JJJTZSMCompleteUKInfra01/12/201914/12/2020100%  Y Y    

 

 

 

 

From this data in excel I have created the following so that I can then create a chart.  I would like to have the ability to drill back to the underlying data:

Sub table - Book of Work Excel Formula
Current Book of Work10=COUNTA(A2:A11)
Live Projects8=COUNTIF(K2:K11,"<100%")
Delivered Projects1=COUNTIF(K2:K11,"=100%")
Missed Chance5=COUNTIF(L2:L11,"Late")

 

What is the best approach for this in Power BI?

 

I have tried the following:

I have reated a reference table in the transform data area, highlighted, Project No, % Complete, and Missed Chance.  I then unpivoted the data which flattened the data, however i can get the count of projects (Current Book of Work) to be correct, however i cannot get the other values correct.  In addition doing it this way i dont think i can drill to the underlying data.

 

Any assistance on this would be appreciated, i have attached an excel version of the formulas and the charts that are needed.

 

Thanks in advance.

Screenshot 2020-11-17 at 09.08.48.png

 

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @Mal_Sondh,

I think duplicate and unpivoted raw table value fields should be a great idea to reduce the formula complexity.

After these steps, you can use the switch function to switch different calculation expressions based on the current category type. (filter on current category and specific attribute fields type with conditions)

Measure =
VAR currCate =
    SELECTEDVALUE ( Table[Category] )
RETURN
    SWITCH (
        currCate,
        "Current Book of Work", COUNTROWS ( VALUES ( Table[Project No] ) ),
        "Live Projects",
            CALCULATE (
                COUNTROWS ( Table ),
                FILTER (
                    ALLSELECTED ( Table ),
                    [Attribute] = "% Complete"
                        && VALUE ( Table[Value] ) < 1
                )
            ),
        "Delivered Projects",
            CALCULATE (
                COUNTROWS ( Table ),
                FILTER (
                    ALLSELECTED ( Table ),
                    [Attribute] = "% Complete"
                        && VALUE ( Table[Value] ) = 1
                )
            ),
        "Missed Chance",
            CALCULATE (
                COUNTROWS ( Table ),
                FILTER (
                    ALLSELECTED ( Table ),
                    [Attribute] = "%Missed Change"
                        && Table[Value] = "Late"
                )
            )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @Mal_Sondh,

I think duplicate and unpivoted raw table value fields should be a great idea to reduce the formula complexity.

After these steps, you can use the switch function to switch different calculation expressions based on the current category type. (filter on current category and specific attribute fields type with conditions)

Measure =
VAR currCate =
    SELECTEDVALUE ( Table[Category] )
RETURN
    SWITCH (
        currCate,
        "Current Book of Work", COUNTROWS ( VALUES ( Table[Project No] ) ),
        "Live Projects",
            CALCULATE (
                COUNTROWS ( Table ),
                FILTER (
                    ALLSELECTED ( Table ),
                    [Attribute] = "% Complete"
                        && VALUE ( Table[Value] ) < 1
                )
            ),
        "Delivered Projects",
            CALCULATE (
                COUNTROWS ( Table ),
                FILTER (
                    ALLSELECTED ( Table ),
                    [Attribute] = "% Complete"
                        && VALUE ( Table[Value] ) = 1
                )
            ),
        "Missed Chance",
            CALCULATE (
                COUNTROWS ( Table ),
                FILTER (
                    ALLSELECTED ( Table ),
                    [Attribute] = "%Missed Change"
                        && Table[Value] = "Late"
                )
            )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
HotChilli
Super User
Super User

Leave the data as it is.

I'm pretty sure you can write measures to get all the results you want.

Start with this:

ProjectCount = COUNT(Table[Project No])

The other measures can use this - just add filter clauses e.g.

Live Projects = CALCULATE([ProjectCount], Table[% Complete] < 1)

 

 

The Average and Min measures - You will have to write measures for each column i.e. communication

Thanks @HotChilli I dont think measures will do it as the measures can only be used in the chart values and not in the Axis or Legend.

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.