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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
bagabo
Frequent Visitor

Calculating a Sum of Max Values in an array (of Slicers-Values)

Hi! 

I built myself an Index of System-installs, so i can calculate the max(index) of some Period (e.g. 2021, December) and have the correct Number of installed Systems at the end of this month.

This works just fine for one system checked on a slicer. However, if i want to know how much of a System-family (like 2 similar systems), I'd need to calculate a sum of these two maxed values. 

 

Sum of System Index Measure = 
    VAR _SystemArray = VALUES([System])   //Array of systems

RETURN

?

Usual: MAX([System] <- SUM for all chosen systems

 

As in the image, I would create an array with all the systems the user chose in the slicer. But how do I sum up all of the max(Index) of this array of systems?

Thankful for any information!

Regards

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

Hi @bagabo ,

 

Based on my max measure , I used system and date as grooups. So when you use hierarchy and drill down, it will not return correct values. 

 

So to my knowledge, you could use HASONEVALUE() to catch the correct hierarchy, as shown below:

test hasonefilter =
IF (
    HASONEFILTER ( Tabelle[Date].[Tag] ),
    1,
    IF (
        HASONEFILTER ( Tabelle[Date].[Monat] ),
        2,
        IF (
            HASONEFILTER ( Tabelle[Date].[Quartal] ),
            3,
            IF ( HASONEFILTER ( Tabelle[Date].[Jahr] ), 4 )
        )
    )
)

hasonefilter.gif

 

 

 

 

So please try:

by year = CALCULATE(MAX('Tabelle'[Index]),FILTER('Tabelle',[System]=MAX('Tabelle'[System]) && YEAR([Date])=YEAR(MAX('Tabelle'[Date])))) 
by quarter = CALCULATE(MAX('Tabelle'[Index]),FILTER('Tabelle',[System]=MAX('Tabelle'[System]) && QUARTER([Date])=QUARTER(MAX('Tabelle'[Date]))))
by month = CALCULATE(MAX('Tabelle'[Index]),FILTER('Tabelle',[System]=MAX('Tabelle'[System]) && MONTH([Date])=MONTH(MAX('Tabelle'[Date]))))
Measure 2 = 
var _year=SUMMARIZE(ALLSELECTED(Tabelle),[Date].[Jahr],[System],"max",[by year])
var _yearsum=SUMX(_year,[max])

var _quarter=SUMMARIZE(ALLSELECTED(Tabelle),[Date].[Quartal],[System],"max",[by quarter])
var _quartersum=SUMX(_quarter,[max])

var _month=SUMMARIZE(ALLSELECTED(Tabelle),[Date].[MonthNo],[System],"max",[by month])
var _monthsum=SUMX(_month,[max])


return  
IF(HASONEFILTER(Tabelle[Date].[Tag]),[sum of max],   IF(HASONEFILTER(Tabelle[Date].[Monat]),_monthsum,  IF(HASONEFILTER(Tabelle[Date].[Quartal]),_quartersum, IF(HASONEFILTER(Tabelle[Date].[Jahr]),_yearsum))))

hierarchy.gif

 

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
v-eqin-msft
Community Support
Community Support

Hi @bagabo ,

 

Based on my max measure , I used system and date as grooups. So when you use hierarchy and drill down, it will not return correct values. 

 

So to my knowledge, you could use HASONEVALUE() to catch the correct hierarchy, as shown below:

test hasonefilter =
IF (
    HASONEFILTER ( Tabelle[Date].[Tag] ),
    1,
    IF (
        HASONEFILTER ( Tabelle[Date].[Monat] ),
        2,
        IF (
            HASONEFILTER ( Tabelle[Date].[Quartal] ),
            3,
            IF ( HASONEFILTER ( Tabelle[Date].[Jahr] ), 4 )
        )
    )
)

hasonefilter.gif

 

 

 

 

So please try:

by year = CALCULATE(MAX('Tabelle'[Index]),FILTER('Tabelle',[System]=MAX('Tabelle'[System]) && YEAR([Date])=YEAR(MAX('Tabelle'[Date])))) 
by quarter = CALCULATE(MAX('Tabelle'[Index]),FILTER('Tabelle',[System]=MAX('Tabelle'[System]) && QUARTER([Date])=QUARTER(MAX('Tabelle'[Date]))))
by month = CALCULATE(MAX('Tabelle'[Index]),FILTER('Tabelle',[System]=MAX('Tabelle'[System]) && MONTH([Date])=MONTH(MAX('Tabelle'[Date]))))
Measure 2 = 
var _year=SUMMARIZE(ALLSELECTED(Tabelle),[Date].[Jahr],[System],"max",[by year])
var _yearsum=SUMX(_year,[max])

var _quarter=SUMMARIZE(ALLSELECTED(Tabelle),[Date].[Quartal],[System],"max",[by quarter])
var _quartersum=SUMX(_quarter,[max])

var _month=SUMMARIZE(ALLSELECTED(Tabelle),[Date].[MonthNo],[System],"max",[by month])
var _monthsum=SUMX(_month,[max])


return  
IF(HASONEFILTER(Tabelle[Date].[Tag]),[sum of max],   IF(HASONEFILTER(Tabelle[Date].[Monat]),_monthsum,  IF(HASONEFILTER(Tabelle[Date].[Quartal]),_quartersum, IF(HASONEFILTER(Tabelle[Date].[Jahr]),_yearsum))))

hierarchy.gif

 

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-eqin-msft
Community Support
Community Support

Hi @bagabo ,

 

Please try:

max = CALCULATE(MAX('Tabelle'[Index]),ALLEXCEPT(Tabelle,Tabelle[System],Tabelle[Date]))
sum of max = 
VAR _TABLE= FILTER(DISTINCT(Tabelle),[Index]=[max])
RETURN SUMX(_TABLE,[Index])

Output:

Eyelyn9_0-1641952104280.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Any further information? Your input was quiet helpful so far!

Hi @v-eqin-msft 

This works pretty good if selected a single Date value. After a Drillup to like Month, Quarter or Year the result gets wrong. Screenshot 2022-01-12 101004.png

As you can see in the image, if "year" selected, the reuslt is 9. I'd expect it to be still 6, as it's still the maximum number of installed systems in this year.

Regards

bagabo
Frequent Visitor

Hi! @v-eqin-msft @amitchandak 

I built a little demo dataset: Sum_of_max_values.pbix 

 

As you can see in the image, i got 3 system types with an index and date. The index stands for the cumulative number of installed systems.
For example: On 02.01.2020 i got a total of 3 Systems of type A. (1 System before, 2 installs on 02.01.2020)

This works by using the max-function in the visuals. The problems occurs if im selecting 2 or more systems.


Screenshot 2022-01-11 103826.png



Like in the picture, system A and system C are selected.
For 02.01.2020: MAX System A: 3
                         MAX System C: 3

So in total i want to count 6 systems. However, because of the max function it shows only 3. 
So i'd need to somehow calculate a sum of these individual max-values of a selected slicer-array.

I hope it is now a little more understandable

Gabriel

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-eqin-msft
Community Support
Community Support

Hi @bagabo ,

 

Sorry for that the information you have provided is not making the problem clear to me. Can you please share more detail information to help us clarify your scenario?

 

Refer to:

How to Get Your Question Answered Quickly

How to provide sample data in the Power BI Forum

 

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@bagabo ,
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.