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
Anonymous
Not applicable

Rank/Classement top 2 YTD par service

Bonjour, 

 

Je suis bloquée sur un problème et j'ai besoin de vos lumières pour m'en sortir 🙂

J'ai une table qui a pour clé : code_commande + code_position. Une commande peut avoir plusieurs positions (=lignes de commande).

Une commande est faite par un service.

Mon but est d'afficher le top 2 des commandes par service par mois sélectionné --> ça j'y arrive.

Et de faire la même chose en year-to-date, c'est à dire afficher le top 2 pour l'année sélectionnée jusqu'au mois maximum sélectionné --> c'est là que je suis bloquée 😞

Voici un exemple de jeu de données pour que vous compreniez mieux : 

Code_commandecode_positionserviceidfournisseurobjet_commandedate_creation_cdeperiodemontant_position_eurmontant commande totalrank pour la periode par service
11ATF1xxx01/01/202020-015011001
12ATF1xcyxc01/01/202020-01900
13ATF1x01/01/202020-01150
21GIF5a03/01/202020-0110105
31GIF1dvc10/01/202020-01100012502
32GIF1sdvf10/01/202020-01250
41ATF215/01/202020-01801802
42ATF215/01/202020-01100
51ATF516/01/202020-011501503
61GIF1017/01/202020-0125254
71GIF1218/01/202020-01100510053
81GIF319/01/202020-01150015001
          
91GIF3sdf15/02/202020-02302003
92GIF3sdf15/02/202020-0240
93GIF3sdf15/02/202020-0260
94GIF3sdfs15/02/202020-0245
95GIF3dfsd15/02/202020-0225
101ATF12f17/02/202020-02120012001
11 GIF10 18/02/202020-02130013001
12 GIF6 19/02/202020-023503502
13 ATF1 20/02/202020-0227604
13 ATF1 20/02/202020-0233
14 ATF2 22/02/202020-021001003
15 ATF5 23/02/202020-024004002

 

 

Pour le top 2 par service en vue mensuelle, j'arrive à obtenir cela : 

vue mensuelle    
top 2 des commandes par service    
période sélectionnée :code_commandeservicemontant_commanderank par service
2020-018GI15001
 3GI12502
 1AT11001
 4AT1802
     
2020-02code_commandeservicemontant_commanderank par service
 11GI13001
 10AT12001
 15AT4002
 12GI3502

Pour cela, je fais une table calculée de cette manière : 

=SUMMARIZECOLUMNS(Factcommandes[Service]; DimFournisseur[nomfournisseur];Factcommandes[Code_commande];Factcommandes[objet_commande];Factcommandes[periode]; "Valeur Nette cde";sum(Factcommandes[montant_position_EUR]) )

 

et je créé une colonne pour calculer le rank par periode, par service : 

=RANKX(

Filter (

TableSummarize;

TableSummarize[Service]=EARLIER(TableSummarize[Service])

&&

TableSummarize[periode]=EARLIER(TableSummarize[periode])

 

)

;TableSummarize[Valeur Nette cde]

;

;DESC

;Dense

)

Ensuite, dans mon rapport, je filtre rank <=5. ça fonctionne parfaitement.

 

Maintenant, là où je n'y arrive pas, c'est pour faire la même chose en vue YTD.

Je veux obtenir ça : 

vue YTD     
top 2 des commandes par service     
période sélectionnée :code_commandeservicemontant_commanderank YTD par service 
2020-018GI15001résultat YTD identique à la vue mensuelle de 2020-01
 3GI12502 
 1AT11001 
 4AT1802 
      
2020-02code_commandeservicemontant_commanderank YTD par servicemois de la commande
 8GI15001janvier
 11GI13002février
 10AT12001février
 1AT11002janvier

 

Avez-vous des idées pour y parvenir ?

Merci beaucoup, AnneSo

 

1 ACCEPTED SOLUTION

@Anonymous 

The tricky part is that you want to do the ranking over the whole YTD period, not only the cumulative sum. To follow on your initial approach, you can create this calculated table:

 

CumulativeTable =
GENERATE (
    SELECTCOLUMNS (
        DISTINCT ( Factcommandes[periode] ),
        "BasePeriode", Factcommandes[periode]
    ),
    VAR baseT_ =
        CALCULATETABLE (
            ADDCOLUMNS (
                SUMMARIZE (
                    Factcommandes,
                    Factcommandes[Service],
                    Factcommandes[Code_commande],
                    Factcommandes[periode]
                ),
                "CUMULATIVE Valeur Nette cde",
                    CALCULATE (
                        SUM ( Factcommandes[montant_position_EUR] ),
                        ALLEXCEPT (
                            Factcommandes,
                            Factcommandes[service],
                            Factcommandes[Code_commande]
                        ),
                        FILTER (
                            ALL ( Factcommandes[periode] ),
                            Factcommandes[periode] <= MAX ( Factcommandes[periode] )
                        )
                    )
            ),
            Factcommandes[periode] <= EARLIER ( [BasePeriode] )
                && YEAR ( Factcommandes[periode] ) = YEAR ( EARLIER ( [BasePeriode] ) )
        )
    VAR addRankT_ =
        ADDCOLUMNS (
            baseT_,
            "CumulativeRank_",
                RANKX (
                    FILTER ( baseT_, [Service] = EARLIER ( [Service] ) ),
                    [CUMULATIVE Valeur Nette cde],
                    ,
                    DESC,
                    DENSE
                )
        )
    RETURN
        addRankT_
)

 

 

Then you can add to the visual BasePeriode (newly created) and  the other columns you already had. You can also set a slicer on basePeriode; in this case, you probably do not need it on the visual. Another option would be to do all this with measures rather than through calculated tables. It'd be more flexible and probably easier.

See it all at work in the attached file.

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Oh my god, you rockkkkkkkkk!!!!!!!! 

I was really hopeless when posting this yesterday on the forum, quite complex for anyone but you did it!!!!

I just had to change a small thing, to calculate the rank, it wasn't calculated by service, I have put this formula instead in a separated column : 

= RANKX(

Filter (

CumulativeTable;

CumulativeTable[Service]=EARLIER(CumulativeTable[Service])

&&

CumulativeTable[BasePeriode]=EARLIER(CumulativeTable[BasePeriode])

 

)

;CumulativeTable[CUMULATIVE Valeur Nette cde]

;

;DESC

;Dense

)

 

But again, whaouuuuuuuuuuuuuuu!!! Thanks a million AIB, you make my day (and even my week ^^ )! 

Anonymous
Not applicable

Hi, 

 

Yes, DimFournisseur is built on a classic manner : 

id | code_fournisseur | country | Nomfournisseur | datedebValidite | datefinvalidite | activeFlag

 

@Anonymous 

The tricky part is that you want to do the ranking over the whole YTD period, not only the cumulative sum. To follow on your initial approach, you can create this calculated table:

 

CumulativeTable =
GENERATE (
    SELECTCOLUMNS (
        DISTINCT ( Factcommandes[periode] ),
        "BasePeriode", Factcommandes[periode]
    ),
    VAR baseT_ =
        CALCULATETABLE (
            ADDCOLUMNS (
                SUMMARIZE (
                    Factcommandes,
                    Factcommandes[Service],
                    Factcommandes[Code_commande],
                    Factcommandes[periode]
                ),
                "CUMULATIVE Valeur Nette cde",
                    CALCULATE (
                        SUM ( Factcommandes[montant_position_EUR] ),
                        ALLEXCEPT (
                            Factcommandes,
                            Factcommandes[service],
                            Factcommandes[Code_commande]
                        ),
                        FILTER (
                            ALL ( Factcommandes[periode] ),
                            Factcommandes[periode] <= MAX ( Factcommandes[periode] )
                        )
                    )
            ),
            Factcommandes[periode] <= EARLIER ( [BasePeriode] )
                && YEAR ( Factcommandes[periode] ) = YEAR ( EARLIER ( [BasePeriode] ) )
        )
    VAR addRankT_ =
        ADDCOLUMNS (
            baseT_,
            "CumulativeRank_",
                RANKX (
                    FILTER ( baseT_, [Service] = EARLIER ( [Service] ) ),
                    [CUMULATIVE Valeur Nette cde],
                    ,
                    DESC,
                    DENSE
                )
        )
    RETURN
        addRankT_
)

 

 

Then you can add to the visual BasePeriode (newly created) and  the other columns you already had. You can also set a slicer on basePeriode; in this case, you probably do not need it on the visual. Another option would be to do all this with measures rather than through calculated tables. It'd be more flexible and probably easier.

See it all at work in the attached file.

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

AlB
Super User
Super User

Bonjour @Anonymous 

Can you please share the contents of the DimFournisseur table as well?

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

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.

Top Solution Authors