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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

translate DAX to M

Hello all,

 

In dax I created a parent column for all my tasks. But I need to call it in a function. So I have to reproduce it in M from the query editor. I don't know the M code well.

Can you help me please?

 

My column :

Parent =

var Niveau = 'rapport jalon'[Niveau hiérarchique]
var CodeProjet = 'rapport jalon'[Code projet]
var Index = 'rapport jalon'[Index]
var IndexR =MAXX(FILTER(ALL('rapport jalon'),'rapport jalon'[Code projet]=CodeProjet && 'rapport jalon'[Niveau hiérarchique]<Niveau && 'rapport jalon'[Index]<Index),'rapport jalon'[Index])
var Jalon = 'rapport jalon'[Jalon]

return


IF(Jalon="oui",SUMMARIZE(FILTER('rapport jalon','rapport jalon'[Index]=IndexR),'rapport jalon'[Tâches]))
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tVjJbuNGE36Vhk82vLG5irnJMu04vxQTkmIMkARBm2rLjVCkfjYp2PM0OUbPoRdLVS8kpVEwM5nk4EVd1bV8VV2Lfv75hDonFycUfka5yF7fyZhvWJ6XQpLvyFAWYvdnxSWZpY9zcs8qTn4jU74qi3q35eRmmnw/nJO8zPz45NcLEIaCXPhJX5nkZJoM9TEeeXhclcuKrVZcH+ORj6rLQoplAXoWnMhGbAQ5J3ejW83l28s5KySpefZaiP83XGpqYGQkdQOX0zmZ8JmmhObeJJmRzGggG17VnMx+enh6UFyudT9x3WDgkEsyuXdJmpDAJdPd9oVntSgLstvWrMhed1sBjgOT9cy1Dk9uUzgeSslXzzlbcpILCYrW1W67ERJEFDzPOfq3YiCiEjzXDrjunoQp3zTA9kvjOG7E38SSF5lx1fX2OG9Z3TEWm1KQRQPyQRtJRo/6RtA5F1LtnIfOeeAphFFAjLh2rkbcQeDuD4L21hCLfLddshyDopWwalUKTAbPdZzNldYQGpuSBE0aJfp00OmN3Vi5tVrn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JRZLkodltroH3he0+Nun5rROiEai6DOedFZPrFGsmE+pdOjCXVTtCqD3Rzlp5noH+BFUZwcFxf1Onz1ID+Y7lEn+4rXn887DDkhTdvCEPOVmusnawiq3LR4IwOpwtRovu9oLs28T474FI1aKt5LPlAkuu5WdCc3uklnhP6ZEhuZ7ofqooH+wLgDTnT1bfR4glxSsdvAFMNU2nKKuxATBT15Zh9xI0S6DfYBAqCjtxUzbueObEn2tYZQBGZqfZ3MOdQz6baXgejnk0nmDE2DGB7uAPoIcllk8OgrrPGjJQgdlSJWmRqdMeZAZ4RsC61F7AwXfVA9exyc7Djev1VBR+Wmm+UbkBOSui8Zp9ttxUlAJ4m1khYTJRN8DrUDgQAfYBsqBakACtwzuL1XkbjMcsFhrXtINS3K09/EVZzfX8PgpbQox5u4WqC68i+Ie+NehWaaxoLbUf049OgYQr3vYbFW59H1mJ7rtGAoHuGAwEPeqFMITaQ+6zW62h3MbU3MBSo7xYejNj9CVMfvCccNtUXDLzaiKxnmhq8owN8Lnt0+hm6a+gAmi3CPSwNk2e8wMgATikMkr4h+YbUdWaUBErUiA/VGJivO/bggF1z241AsV9b3tDw6gcMM6dYdK9zOjJc0QHC+tHBVFmxDMtYJrBfYBV6mtHoAqfzNWYAfKK0XwjFag2VWBPcMyN9YKJhmgGus1WFL6Q26jAo4AgYJ1m7+NEg3suYwHGeyenEKJqZIKbDB9SfFBlbVLheGaVquEdcH76fnJsjaiPQ7gJq62jqEvdrtVFPHmbz6XBMfrw3d1xje3cHBUI7WaB2x7lywabdHz+QO/WdEjknKSQckKBpvLbbLg09kyL6a6prssHWahuL4fE/pwsCcsNy9o7Y7baQ/qqBn+uvswCVQwwCo1RtdfteD/teX5MeSnYVNMURADYEmySWoITOeww2zpahVWgzN4yNQQeLH6QT8LJeO4owfINjppPZp5kSUYucMefXvwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, #"Level task" = _t, task = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Index", Int64.Type}, {"Level task", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "parent task", each Table.Max(Table.SelectRows(#"Changed Type",(k)=> [Level task]=k[Level task]+1 and [Index]>k[Index]),"Index")[task]),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom", {{"parent task", ""}})
in
    #"Replaced Errors"

View solution in original post

12 REPLIES 12
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tVjJbuNGE36Vhk82vLG5irnJMu04vxQTkmIMkARBm2rLjVCkfjYp2PM0OUbPoRdLVS8kpVEwM5nk4EVd1bV8VV2Lfv75hDonFycUfka5yF7fyZhvWJ6XQpLvyFAWYvdnxSWZpY9zcs8qTn4jU74qi3q35eRmmnw/nJO8zPz45NcLEIaCXPhJX5nkZJoM9TEeeXhclcuKrVZcH+ORj6rLQoplAXoWnMhGbAQ5J3ejW83l28s5KySpefZaiP83XGpqYGQkdQOX0zmZ8JmmhObeJJmRzGggG17VnMx+enh6UFyudT9x3WDgkEsyuXdJmpDAJdPd9oVntSgLstvWrMhed1sBjgOT9cy1Dk9uUzgeSslXzzlbcpILCYrW1W67ERJEFDzPOfq3YiCiEjzXDrjunoQp3zTA9kvjOG7E38SSF5lx1fX2OG9Z3TEWm1KQRQPyQRtJRo/6RtA5F1LtnIfOeeAphFFAjLh2rkbcQeDuD4L21hCLfLddshyDopWwalUKTAbPdZzNldYQGpuSBE0aJfp00OmN3Vi5tVrnLOMrXtRktdtmrBByBbKG94S6zwvEDuBVuZaWiJyrJcWHCUVOwUSQVYgXwaszxeU5R/PLo5/k17SUmM2hptu0vC2zBi2THfBgYoOR19B7FsgxdRznMv3dj88DGlz+bYZMb/2BvmkBehz2APLiFiAvjgY2MDMShP4+VvJdgjzIGUx5lT498FQ2FSVvNvAwJRhCMkyugkGYyGk6G599RyDsUptY8KaSOmy+Y6ya98Pmuz2rBtFeTFwyfJaYi6g0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3MOdQz6baXgejnk0nmDE2DGB7uAPoIcllk8OgrrPGjJQgdlSJWmRqdMeZAZ4RsC61F7AwXfVA9exyc7Djev1VBR+Wmm+UbkBOSui8Zp9ttxUlAJ4m1khYTJRN8DrUDgQAfYBsqBakACtwzuL1XkbjMcsFhrXtINS3K09/EVZzfX8PgpbQox5u4WqC68i+Ie+NehWaaxoLbUf049OgYQr3vYbFW59H1mJ7rtGAoHuGAwEPeqFMITaQ+6zW62h3MbU3MBSo7xYejNj9CVMfvCccNtUXDLzaiKxnmhq8owN8Lnt0+hm6a+gAmi3CPSwNk2e8wMgATikMkr4h+YbUdWaUBErUiA/VGJivO/bggF1z241AsV9b3tDw6gcMM6dYdK9zOjJc0QHC+tHBVFmxDMtYJrBfYBV6mtHoAqfzNWYAfKK0XwjFag2VWBPcMyN9YKJhmgGus1WFL6Q26jAo4AgYJ1m7+NEg3suYwHGeyenEKJqZIKbDB9SfFBlbVLheGaVquEdcH76fnJsjaiPQ7gJq62jqEvdrtVFPHmbz6XBMfrw3d1xje3cHBUI7WaB2x7lywabdHz+QO/WdEjknKSQckKBpvLbbLg09kyL6a6prssHWahuL4fE/pwsCcsNy9o7Y7baQ/qqBn+uvswCVQwwCo1RtdfteD/teX5MeSnYVNMURADYEmySWoITOeww2zpahVWgzN4yNQQeLH6QT8LJeO4owfINjppPZp5kSUYucMefXvwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, #"Level task" = _t, task = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Index", Int64.Type}, {"Level task", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "parent task", each Table.Max(Table.SelectRows(#"Changed Type",(k)=> [Level task]=k[Level task]+1 and [Index]>k[Index]),"Index")[task]),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom", {{"parent task", ""}})
in
    #"Replaced Errors"
Anonymous
Not applicable

perfect ! thank you so much !

Anonymous
Not applicable

This is the 14th. It is always the closest line above when following the order of the index.

lbendlin
Super User
Super User

For index 15, is the parent index 14  or index 12 ?

Anonymous
Not applicable

You can see the expected result with my column created in dax. Now I need to create it from the query editor to call it in a function. Something I can't do with a column calculated in dax

CharlyExperteam_1-1627314266165.png

 

 

 

lbendlin
Super User
Super User

Are these tasks all for the same project?

Anonymous
Not applicable

There are several projects and there can be several task hierarchies in one project. That's why the project column is not present. It is not mandatory here. The only thing I need is to know the parent task for each task. 

Anonymous
Not applicable

IndexLevel tasktask
101Clichy Levallois : Asnières SPOT Gare _ Remontée BREHAT loc49
112Phase REA
123Programme
134Consignes de suivi + FCD
143Plans techniques
154Etude PT MeS
163MES consigne verte SUIVI
201E22580 - MG2 PE 52 Réfection étanchéité - REA
212MDP - Assemblage liste prévisionnelle de matériels
222MDP - Revue d'exigences
232MDP - Date d'envoi du devis ECO
251E22610 - MG3 PE 380 Remise en état suite à visites légales d'armoires 3200v.
262EE - DCE
281E22929 - Remplacement mécanismes AG 12bd - Achères Poste 2
292Phase REA (à planifier)
303Programme
314Consignes Roses S6
323Documents d'exécutions
351L1000-Pk49+515-Réfection étanchéité RD48
362OA - DCE
391E23978 - MG3 PS 564 Remplacement systématique de mécanismes de manoeuvre sect caténaire (PSL): 10 sectionneurs.
402TE - DCE
421E23987 - Achères P2 Absence de crocodile au panneau C47
432Phase REA (à planifier)
443Documents d'exécution
454Etudes DEX
471E23999 - MG3 PS 586 RP Renforcée, remplacement constituants et armement type 85
482TE - DCE
491E23999 - MG3 PS 586 RP Renforcée, remplacement constituants et armement type 85
502TE - DCE
531E24014 - CBT S11 pour SEL 186 Batignolles
542Phase REA
553Consignes
564PR - Consigne Bleue S11 Temporaire
573MES consigne bleue S11 Temporaire
591E25121 - OGE - Traitement des absences de découplage de la sous-station Berthier suite à rapport d'audit sur PSL - Programme 2019
602EE - DCE
641E25376 - FEM 07686 - MG3 PSE 411 Remplacement des batteries et chargeurs du poste mixte GREE de Valmy poste1 et des relais de protection des postes de Berlioz (x1), poste 43 (x3) et poste F (x3).1 batterie et 7 relais Sepam.
652EE - DCE
831E26744 - Pra chemin des piécottes (L1000 - Pk 91+927) - DCE
841E26744 - Pra chemin des piécottes (L1000 - Pk 91+927) - REA
852MDP - Assemblage liste prévisionnelle de matériels
862MDP - Revue d'exigences
872MDP - Date d'envoi du devis ECO
921F28652 - Renouvellement de la Sous station des Saugées
932TE - DCE
951Phase REA
962Programme
973Consignes S6
983Consignes S11
992MeS
1031PRo du Périchois à Grandpuits - renouvellement de la culée C0. - PRO
1042MDP - Assemblage liste prévisionnelle de matériels
1052MDP - Revue d'exigences
1062MDP - Date d'envoi du devis ECO
1071PRo du Périchois à Grandpuits - renouvellement de la culée C0. - DCE
1082OA - DCE
1092EG - DCE
1101PRo du Périchois à Grandpuits - renouvellement de la culée C0. - REA
1112MDP - Assemblage liste prévisionnelle de matériels
1122MDP - Revue d'exigences
1132MDP - Date d'envoi du devis ECO
1161F32505 - Ligne VMC Km 33 à Km 53 - Renforcement des massifs des supports caténaires inclinés
1172TE - DCE
1241F36068 - Modification support 14-09 et mise en place sectionnements courts
1252TE - DCE
1271F36310 - Nogent Gretz Remplacement de feux à lampes par modules à diodes - REA
1282Documents d'exécutions
1293DEX E/T
1303DEX - E/T 1V
1321F36462 - Régénération des CdV et PLx entre Paris Saint-Lazare et Bécon les Bruyères et du poste 5 PRS de Batignolles
1332EE - DCE
1361Travaux IFTE résultant des Etudes de Criticité sur la région de PE.- REA
1381Phase REA
1392Phasage - Travaux - Essais
1403Phase 111 - Pose des voies PointX Nord non MES et caténaires non alimentées
1414PT MeS
1424Consigne S6 MeS
1434Consigne S11 MeS
1444MES consigne rose S6
1454MES consigne bleue S11
1463Phase 120
1474Phase 120 - Poste 3
1485Travaux Préparatoires Phase 120 P3
1496Deuxième retrait de service S11
1507Consigne S6 - S11
1517Consigne S6 - S11
1527MeS de la consigne S11
1535PT MES P3 P4
1545Consignes MeS S6 pour le P3 / P4
1555Consigne MeS S11 pour le P3/4
1565DEX - Validation des RC
1575Travaux poste 3 (raccourcissement VS17, dépose VS111 et mise en impasse VS112)
1586MDP - Démarrage travaux de signalisation
1593Phase 500b (Mise en Service PAI et Encadrants)
1604IHM+
1615Programme des automatismes MISTRAL NG
1626Programme IHM+ indice 00.2 (MàJ FSUIVI + Pièce fichier)
1637Etude / vérification
1646Programme IHM+ indice 00.3 (Balayage étoilage + SUIVI encadrants)
1657PR - Programme des Automatismes / IHM+
1664Etudes PAI
1675Etudes PR - PT PAI
1686Etudes Programme P4
1697Traitement des dérogations
1708PR - Programme de Signalisation
1716PT PAI
lbendlin
Super User
Super User

At the very minimum you need an index column in your source data.

Please provide sample data in usable format (not as a picture) .

v-xulin-mstf
Community Support
Community Support

Hi @Anonymous,

 

Without data structure, i'm not clear about your expected output.

Could you provide sample data and expected output after removing sensitive data?
Sample data and expected output would help tremendously.

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

Anonymous
Not applicable

Hello 🙂

In the same project, I have several sub-projects composed of several tasks.

What I want is to get the parent of each task. I have in my data a column with the hierarchical level of each task. The parent of a task is always the row with the first lower level closest to the top of the table.

By highlighting in my example the result I want to get in the query editor.

 

CharlyExperteam_0-1627304605457.png

 

 

lbendlin
Super User
Super User

Determining the maximum value in a M column is a costly operation. How many rows do you have?

 

Please provide sample data in usable format (not as a picture) and show the expected outcome.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors