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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Toine40
Regular Visitor

Extract the whole line of a table containing the maximum value

Hi everyone, 
I have this table, in which each line represents a stop cause and the duration of each stop :

Toine40_0-1734173618084.png

I manage to create a table to sum the stop duration and group by stop cause with this formula : 

Tab_Cause_Arret_maxi =
SUMMARIZECOLUMNS
(
'Arrêts'[Date],'Arrêts'[Libellé Motif],
FILTER('Arrêts','Arrêts'[Type d'arrêt] IN {"ARE", "AI", "ANQ"} && 'Arrêts'[Atelier]="U2_M_DECOUPE"),
"Tps_maxi",SUM('Arrêts'[Temps (en min)])
)
Here's the result :

Toine40_1-1734173679717.png

What I would like now is to get only the first line, corresponding to the maximum stop cause 
I manage to get the max stop duration with this formula : 

CAUSE MAX = MAXX(Tab_Cause_Arret_maxi,Tab_Cause_Arret_maxi[Tps_maxi])


Toine40_2-1734173887891.png

But what I want is the whole line, sth like this, with the stopo cause and the duration :

Toine40_3-1734173960374.png


Can someone help ?
And maybe there's a way to get the result without creating this new table ?

Thanks to all of you

1 ACCEPTED SOLUTION

Hi @Toine40 

 

Please try this measure:

MEASURE =
VAR _Tab_Cause_Arret_maxi =
    SUMMARIZECOLUMNS (
        'Arrêts'[Date],
        'Arrêts'[Libellé Motif],
        FILTER (
            'Arrêts',
            'Arrêts'[Type d'arrêt]
                IN { "ARE", "AI", "ANQ" }
                    && 'Arrêts'[Atelier] = "U2_M_DECOUPE"
        ),
        "Tps_maxi", SUM ( 'Arrêts'[Temps (en min)] )
    )
RETURN
    CONCATENATEX (
        TOPN ( 1, _Tab_Cause_Arret_maxi, [Tps_maxi], 0 ),
        [Libellé Motif] & " " & [Tps_maxi]
    )

This measure creates a virtual table variable, so that you don't need to create an entity table anymore.

 

Best Regards

Zhengdong Xu
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

6 REPLIES 6
v-zhengdxu-msft
Community Support
Community Support

Hi @Toine40 

 

Please try this measure:

MEASURE =
CONCATENATEX (
    TOPN ( 1, 'Tab_Cause_Arret_maxi', 'Tab_Cause_Arret_maxi'[Tps_maxi], 0 ),
    'Tab_Cause_Arret_maxi'[Libellé Motif] & " " & 'Tab_Cause_Arret_maxi'[Tps_maxi]
)

the result is as follow:

vzhengdxumsft_1-1734319126440.png

 

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thks a lot v-zhengdxu-msft, 

This works fine !!! I'd like we could mix both your answer and the one of DataNinja777 to avoid the creation of a new table, but if we can't you solution is th best. Thanks a lot for this
 
 

Hi @Toine40 

 

Please try this measure:

MEASURE =
VAR _Tab_Cause_Arret_maxi =
    SUMMARIZECOLUMNS (
        'Arrêts'[Date],
        'Arrêts'[Libellé Motif],
        FILTER (
            'Arrêts',
            'Arrêts'[Type d'arrêt]
                IN { "ARE", "AI", "ANQ" }
                    && 'Arrêts'[Atelier] = "U2_M_DECOUPE"
        ),
        "Tps_maxi", SUM ( 'Arrêts'[Temps (en min)] )
    )
RETURN
    CONCATENATEX (
        TOPN ( 1, _Tab_Cause_Arret_maxi, [Tps_maxi], 0 ),
        [Libellé Motif] & " " & [Tps_maxi]
    )

This measure creates a virtual table variable, so that you don't need to create an entity table anymore.

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This is it !!!! Exactly ! Thank you so much @v-zhengdxu-msft 🙏🙏

DataNinja777
Super User
Super User

Hi @Toine40 ,

 

To get the maximum stop cause and its corresponding duration, you can achieve this either by creating a dynamic measure or by defining a calculated table, depending on your needs.

For a dynamic solution without creating a new table, you can write a measure that identifies the maximum stop duration and retrieves the associated stop cause. The measure can be defined as follows:

Max_Stop_Cause = 
VAR MaxDuration = 
    MAXX(
        FILTER(
            'Arrêts',
            'Arrêts'[Type d'arrêt] IN {"ARE", "AI", "ANQ"} &&
            'Arrêts'[Atelier] = "U2_M_DECOUPE"
        ),
        'Arrêts'[Temps (en min)]
    )
VAR MaxRow =
    TOPN(
        1,
        FILTER(
            'Arrêts',
            'Arrêts'[Type d'arrêt] IN {"ARE", "AI", "ANQ"} &&
            'Arrêts'[Atelier] = "U2_M_DECOUPE"
        ),
        'Arrêts'[Temps (en min)],
        DESC
    )
RETURN
    CONCATENATEX(
        MaxRow,
        'Arrêts'[Libellé Motif] & " - " & MaxDuration,
        ", "
    )

This measure dynamically calculates the maximum stop duration by filtering the relevant rows and creates a string combining the stop cause and the maximum duration. 

 

 

Best regards,

Hi @DataNinja777,
This looks so great, that's exactly what I need ! Only thing is the result is

Toine40_0-1734182286778.png

This is the second max cause and not the first one ; I've been trying to understand for more thant 1 hour but can't find the reason

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors