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

Combined total without un pivoting columns

Hi, 

 

I am trying to create a total from multiple columns without having to up pivot said columns. 

 

Here is a sample of the data;

 

EmployerIndustry SectorIndustry Sector 2Industry Sector 3 Employer size categoryNumber of Cadets contractedContract execution dateFinal monitoring report receivedFinancial year
Āhau NZ LimitedInformation media and telecommunications   110/03/20205/10/20202019/20
All Area Scaffolding LimitedConstruction   317/06/201929/11/20192018/19
Broadspectrum (New Zealand) LimitedElectricity, gas, water and waste servicesConstruction 50+15 2/07/20202020/21
Alliance Services LimitedConstruction   29/02/202020/08/20202019/20

 

Im trying to show totals for all three industry columns. An example would be the total for Contstructions would be 3.

 

I cant un pivot the columns because im calculating the "Number of Cadets Contracting" column to show totals for each employer, un pivoting would create duplicated rows and double the totals.

 

Any help would be much appriciated, open to other options that may achieve the same outcome.

 

Thanks.

 

 

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Ngars ,

 

One question regarding the calculation you need to achieve you are presenting on your example that the Total for Constructions would be 3 is this the count of rows that have the Construction on one of the Industry sector?

 

What is the result you are trying to achieve in the calculations, is it to be used in different types of calculations like SUM, AVERAGE, COUNT or to a specific one?

And how do you want to have the values filter is it by a single column or by all columns that you have?

 

I have made a simple exercise making a count of each sector.

 

  • Created a disconnected table with industry I used the code below:
Industry =
FILTER (
    DISTINCT (
        UNION (
            VALUES ( 'Table'[Industry Sector] );
            VALUES ( 'Table'[Industry Sector 2] );
            VALUES ( 'Table'[Industry Sector 3 ] )
        )
    );
    'Table'[Industry Sector] <> BLANK ()
)

 

Now I added the following measure:

Count of industry = 
VAR Industry_selection =
    VALUES ( Industry[Industry Sector] )
VAR Industry_Count =
    FILTER (
        ALLSELECTED ( 'Table'[Industry Sector]; 'Table'[Employer] );
        'Table'[Industry Sector] IN Industry_selection
    )
VAR Industry_2_Count =
    FILTER (
        ALLSELECTED ( 'Table'[Industry Sector 2]; 'Table'[Employer] );
        'Table'[Industry Sector 2] IN Industry_selection
    )
VAR Industry_3_Count =
    FILTER (
        ALLSELECTED ( 'Table'[Industry Sector 3 ]; 'Table'[Employer] );
        'Table'[Industry Sector 3 ] IN Industry_selection
    )
RETURN
    COUNTROWS ( Industry_Count ) + COUNTROWS ( Industry_2_Count )
        + COUNTROWS ( Industry_3_Count )

 

As you can see below I have the count for each industry correctly:

 
 

Screenshot 2020-11-05 152900.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

7 REPLIES 7
Ngars
Helper I
Helper I

Hi @MFelix 

Ok awesome, thanks for that! With that slicer working it looks like the solutiion to my problem. 

Ngars
Helper I
Helper I

Ok, so creating a seperate table might not solve my issue and I also need the Idusries to be filtered by Financial Year.

Hi @Ngars ,

 

The disconnected table is only forcing that the 3 columns are searched for the comoon field that is the industry, however if you look at the part of the formula where you have ALLSELECTED you may choose to add additional columns with other filters in this case add the FY:

 

Count of industry = 
VAR Industry_selection =
    VALUES ( Industry[Industry Sector] )
VAR Industry_Count =
    FILTER (
        ALLSELECTED ( 'Table'[Industry Sector], 'Table'[Employer] ,'Table'[Financial year]),
        'Table'[Industry Sector] IN Industry_selection
    )
VAR Industry_2_Count =
    FILTER (
        ALLSELECTED ( 'Table'[Industry Sector 2], 'Table'[Employer] , 'Table'[Financial year]),
        'Table'[Industry Sector 2] IN Industry_selection
    )
VAR Industry_3_Count =
    FILTER (
        ALLSELECTED ( 'Table'[Industry Sector 3 ], 'Table'[Employer] , 'Table'[Financial year]),
        'Table'[Industry Sector 3 ] IN Industry_selection
    )
RETURN
    COUNTROWS ( Industry_Count ) + COUNTROWS ( Industry_2_Count )
        + COUNTROWS ( Industry_3_Count )

 

Has you can see on the PBIX attach it also works on FY slicer.

 

This is a context problem and so to enforce the context you can add the columns you need to the values, I have made this approach to have the ALLSELECTED based on differents columns but you can also place the table name instead, however this can caus performance issues but result should be similar.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Ngars
Helper I
Helper I

I also have a slicer that filters FY, will creating a seperate Industry table affect this?

The separate table should not affect any other values since it will only impact measures or visualizations where it's mentioned.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @Ngars ,

 

One question regarding the calculation you need to achieve you are presenting on your example that the Total for Constructions would be 3 is this the count of rows that have the Construction on one of the Industry sector?

 

What is the result you are trying to achieve in the calculations, is it to be used in different types of calculations like SUM, AVERAGE, COUNT or to a specific one?

And how do you want to have the values filter is it by a single column or by all columns that you have?

 

I have made a simple exercise making a count of each sector.

 

  • Created a disconnected table with industry I used the code below:
Industry =
FILTER (
    DISTINCT (
        UNION (
            VALUES ( 'Table'[Industry Sector] );
            VALUES ( 'Table'[Industry Sector 2] );
            VALUES ( 'Table'[Industry Sector 3 ] )
        )
    );
    'Table'[Industry Sector] <> BLANK ()
)

 

Now I added the following measure:

Count of industry = 
VAR Industry_selection =
    VALUES ( Industry[Industry Sector] )
VAR Industry_Count =
    FILTER (
        ALLSELECTED ( 'Table'[Industry Sector]; 'Table'[Employer] );
        'Table'[Industry Sector] IN Industry_selection
    )
VAR Industry_2_Count =
    FILTER (
        ALLSELECTED ( 'Table'[Industry Sector 2]; 'Table'[Employer] );
        'Table'[Industry Sector 2] IN Industry_selection
    )
VAR Industry_3_Count =
    FILTER (
        ALLSELECTED ( 'Table'[Industry Sector 3 ]; 'Table'[Employer] );
        'Table'[Industry Sector 3 ] IN Industry_selection
    )
RETURN
    COUNTROWS ( Industry_Count ) + COUNTROWS ( Industry_2_Count )
        + COUNTROWS ( Industry_3_Count )

 

As you can see below I have the count for each industry correctly:

 
 

Screenshot 2020-11-05 152900.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix,

The construction total is a count across all three industry columns. So twice in Industry Sector and once in Industry Sector 2.

The result im trying to achieve in a count of the Industry Values across the three industry columns and im also using a SUM to calculate the "Number of Cadets Contracted", hence why I couldnt use the up pivot method.

Your example looks like what I was trying to achieve. Ill have to run it in my main pbix file and see if it solves my issue.

Thanks

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.