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

How to find sum of max values in a column and filter it?

I have a table that has mutiple values of "OPCount" as rows for each Faciliy name and each date. So i am summing them up to show the max for each day for each facilty. 

Below is what i am using to summarize my rows(Please tell me if this is correct):

1OPCount =
IF(
 
-- NORMAL LINE---
MAXA(Query1[OPCount]),
-- TOTAL LINE ---
SUMX(
VALUES('Query1'[InvDate1]),
CALCULATE(
MAXA(Query1[OPCount])
)
)
)

This is how i get my values - ie: max of among the rows. Butt, I need it to show as total of each column.

 

FeezaAga_1-1598343353851.png

FeezaAga_2-1598343485988.png

 
 
Can you'll suggest a better way to do this so that i clearly get the total of each column whatever filter i may use?
2 ACCEPTED SOLUTIONS

Hi @FeezaAga ,

 

To what I can understand from your data and the result you present is that the values you are picking up are the maximum values for each day correct?

 

I added a new value of 5 to facility A and day 1 in order to get two values for the same date:

MFelix_0-1598449476623.png

Then I made some changes to the measure adding the factory to the sumx:

 

1OPCount =
IF (
    HASONEFILTER ( 'Query1'[EachDay of month ] );
    MAX ( 'Query1'[OPCount] );
    SUMX (
        SUMMARIZE (
            'Query1';
            'Query1'[EachDay of month ];
            Query1[FacilityName];
            "@Max"; MAX ( 'Query1'[OPCount] )
        );
        [@Max]
    )
)

When making use of aggregate functions you need to refer to the columns you need, in this case the result of the summarize table is a table that picks up the value for each facility and each day and a single value for the OPCount.

Having the previous syntax what you are getting is a table with days and a value per each day so you only get the 551 has you final result, that is the higher value at the day level.

 

Check image below and PBIX file attach.

MFelix_1-1598449853037.png

As you can see on facility A day 1 i have 11 and the 5 is not consider and if you sum all the days that are presented you get 1.093.


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

Hi @FeezaAga ,

 

Has refered measures are based in context when in the syntax is refered HASONEFILTER(Table[EachDay]) means that it will check if there is a single value selection for EachDay son when it has one day then it will give MAX other wise is the sum of the values.

When you are filtering on a single day the HASONEFILTER is always true so returns always the maximum value and not the sum try to make the following change to your measure:

1OPCount = 
IF (ISINSCOPE(Query1[EachDay of month ]);
    MAX ( 'Query1'[OPCount] );
   SUMX (
        SUMMARIZE (
            'Query1';
            'Query1'[EachDay of month ];
            Query1[FacilityName];
            "@Max"; MAX ( 'Query1'[OPCount] )
        );
        [@Max]
    )
)

 

Check PBIX file attach:

MFelix_0-1598527693475.png

MFelix_1-1598527716837.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

11 REPLIES 11
MFelix
Super User
Super User

Hi @FeezaAga ,

 

Try the following measure:

 

Maximum Value =
IF (
    HASONEFILTER ( 'Table'[cat] );
    MAX ( 'Table'[Value] );
    SUMX (
        SUMMARIZE ( 'Table'; 'Table'[cat]; "@Max"; MAX ( 'Table'[Value] ) );
        [@Max]
    )
)

 

Be aware that you must adapt the name of the columns to your needs.


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



Thanks so much for the response @MFelix . It seems to give me the values exactly the way i got them before, using my measure.

 

1OPCount =
IF (
HASONEFILTER ( 'Query1'[InvDate1] ),
MAX ( 'Query1'[OPCount] ),
SUMX (
SUMMARIZE ( 'Query1', 'Query1'[InvDate1],"@Max", MAX ( 'Query1'[OPCount] ) ),
[@Max]
)
)
 
 

RESULTRESULT

 

Hi @FeezaAga 

 

The column you must use on the summarization part that I call CAT is the first column on your matrix.

 

So if the InvDate1 is the lowest detail and you must use the column above the invdate looking at your first image is the FacilityName.


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



Thank you @MFelix . if  I use FacilityName it gives me the max value in the whole month for each facility and then sums in the total. I need all the max for each day to be summed up for each facility. Can you think of something for this ?

 

 

Thanks in Advance.

 

 

 

 

 

Hi @FeezaAga ,

 

This is possible but if you can share a sample of your data is easier.

 

Please see this post regarding How to provide sample data in the Power BI Forum (courtesy of @ImkeF).


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



Thank you @MFelix .Below is just three of the main columns of my raw data in picture for this measure...with the sample data.

FacilityNameEachDay of month OPCount
A111
A213
B1254
B2297
C1157
C2220
D189
D252
   

 

Below is what I get when i try to get the max and sum the values. Final 'Total' value gives max of the column which i need it to be the actual total.

1.PNG

Hi @FeezaAga ,

 

To what I can understand from your data and the result you present is that the values you are picking up are the maximum values for each day correct?

 

I added a new value of 5 to facility A and day 1 in order to get two values for the same date:

MFelix_0-1598449476623.png

Then I made some changes to the measure adding the factory to the sumx:

 

1OPCount =
IF (
    HASONEFILTER ( 'Query1'[EachDay of month ] );
    MAX ( 'Query1'[OPCount] );
    SUMX (
        SUMMARIZE (
            'Query1';
            'Query1'[EachDay of month ];
            Query1[FacilityName];
            "@Max"; MAX ( 'Query1'[OPCount] )
        );
        [@Max]
    )
)

When making use of aggregate functions you need to refer to the columns you need, in this case the result of the summarize table is a table that picks up the value for each facility and each day and a single value for the OPCount.

Having the previous syntax what you are getting is a table with days and a value per each day so you only get the 551 has you final result, that is the higher value at the day level.

 

Check image below and PBIX file attach.

MFelix_1-1598449853037.png

As you can see on facility A day 1 i have 11 and the 5 is not consider and if you sum all the days that are presented you get 1.093.


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



WOW @MFelix !! Works beautifully !

 

FeezaAga_0-1598522077759.png

Thank you so much !! It is perfect !! 😀 Really appreciate your help!

Wonder why it does not work when I need to find the total for a single day.

 

FeezaAga_0-1598523919774.png

 

Hi @FeezaAga ,

 

Has refered measures are based in context when in the syntax is refered HASONEFILTER(Table[EachDay]) means that it will check if there is a single value selection for EachDay son when it has one day then it will give MAX other wise is the sum of the values.

When you are filtering on a single day the HASONEFILTER is always true so returns always the maximum value and not the sum try to make the following change to your measure:

1OPCount = 
IF (ISINSCOPE(Query1[EachDay of month ]);
    MAX ( 'Query1'[OPCount] );
   SUMX (
        SUMMARIZE (
            'Query1';
            'Query1'[EachDay of month ];
            Query1[FacilityName];
            "@Max"; MAX ( 'Query1'[OPCount] )
        );
        [@Max]
    )
)

 

Check PBIX file attach:

MFelix_0-1598527693475.png

MFelix_1-1598527716837.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



Thanks !! This is on point ! 🙂 

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.