{"id":12567,"date":"2024-10-02T06:38:42","date_gmt":"2024-10-02T04:38:42","guid":{"rendered":"https:\/\/www.auditsi.eu\/?p=12567"},"modified":"2024-09-28T20:11:48","modified_gmt":"2024-09-28T18:11:48","slug":"dans-certains-cas-power-query-noffre-pas-de-reponse-a-nos-besoins-en-tous-cas-je-ne-suis-pas-parvenu-dans-le-cas-present-a-trouver-une-solution-a-mon-probleme-obtenir-une-balance-comparative-s","status":"publish","type":"post","link":"https:\/\/www.auditsi.eu\/?p=12567","title":{"rendered":"VBA\/SQL vs Power Query : deux solutions compl\u00e9mentaires"},"content":{"rendered":"<p style=\"text-align: justify;\"><strong>Power Query<\/strong>, module int\u00e9gr\u00e9 \u00e0 Excel, pr\u00e9pare les donn\u00e9es brutes (extraction, la transformation et le chargement ou <strong>ETL<\/strong>) en vue d&#8217;une analyse plus approfondie des donn\u00e9es dans Excel. Power Query a beaucoup d&#8217;adeptes (dont moi), notamment ceux qui pr\u00e9conisent le <em>no-code<\/em>. En effet, cet outil <strong>ne n\u00e9cessite pas de connaissance en programmation<\/strong> pour retraiter les donn\u00e9es.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12568\" src=\"https:\/\/www.auditsi.eu\/wp-content\/uploads\/2024\/09\/BG_4ex.png\" alt=\"BG_4ex\" width=\"1133\" height=\"206\" srcset=\"https:\/\/www.auditsi.eu\/wp-content\/uploads\/2024\/09\/BG_4ex.png 1133w, https:\/\/www.auditsi.eu\/wp-content\/uploads\/2024\/09\/BG_4ex-300x55.png 300w, https:\/\/www.auditsi.eu\/wp-content\/uploads\/2024\/09\/BG_4ex-1024x186.png 1024w, https:\/\/www.auditsi.eu\/wp-content\/uploads\/2024\/09\/BG_4ex-768x140.png 768w, https:\/\/www.auditsi.eu\/wp-content\/uploads\/2024\/09\/BG_4ex-730x133.png 730w\" sizes=\"auto, (max-width: 1133px) 100vw, 1133px\" \/><\/p>\n<p style=\"text-align: justify;\">Toutefois, dans certains cas Power Query n&#8217;offre pas de r\u00e9ponse \u00e0 nos besoins&#8230; En tous cas, je ne suis pas parvenu dans le cas pr\u00e9sent \u00e0 trouver une solution \u00e0 mon probl\u00e8me : obtenir une balance comparative sur quatre exercices&#8230; La <strong>difficult\u00e9<\/strong> r\u00e9side dans le fait de lier le plan de comptes (calcul\u00e9 \u00e0 partir des quatre balances) \u00e0 l&#8217;aide de jointures aux quatre balances.<\/p>\n<p>Heureusement, j&#8217;ai trouv\u00e9 une <strong>solution avec un peu de VBA et de SQL<\/strong> :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"visualbasic\">Requete_SQL = \"SELECT [PLAN_COMPTES].CodeEntit\u00e9, [PLAN_COMPTES].CompteNum, [PLAN_COMPTES].CompteLib, [_BG_N].Solde As SoldeN, [_BG_N1].Solde As SoldeN1, SoldeN-SoldeN1 As VarAbs, IIf(SoldeN1&lt;&gt;0,VarAbs\/SoldeN1,0) As VarRel, [_BG_N2].Solde As SoldeN2, [_BG_N3].Solde As SoldeN3, \"\r\nRequete_SQL = Requete_SQL &amp; \"[_BG_N].SoldeSup90j As SoldeSup90j_N, [_BG_N].EF_Libell\u00e9EF As Libell\u00e9EF_N, [_BG_N].RubEF As RubEF_N, [_BG_N1].RubEF As RubEF_N1, [_BG_N].Anomalies As Anomalies_N, CycleCode, \"\r\nRequete_SQL = Requete_SQL &amp; \"IIf([_BG_N].Cpte3 Is Not Null,[_BG_N].Cpte3, IIf([_BG_N1].Cpte3 Is Not Null,[_BG_N1].Cpte3, IIf([_BG_N2].Cpte3 Is Not Null,[_BG_N2].Cpte3,[_BG_N3].Cpte3))) As Cpte3, \"\r\nRequete_SQL = Requete_SQL &amp; \"IIf([_BG_N].Cpte2 Is Not Null,[_BG_N].Cpte2, IIf([_BG_N1].Cpte2 Is Not Null,[_BG_N1].Cpte2, IIf([_BG_N2].Cpte2 Is Not Null,[_BG_N2].Cpte2,[_BG_N3].Cpte2))) As Cpte2, \"\r\nRequete_SQL = Requete_SQL &amp; \"IIf([_BG_N].Cpte1 Is Not Null,[_BG_N].Cpte1, IIf([_BG_N1].Cpte1 Is Not Null,[_BG_N1].Cpte1, IIf([_BG_N2].Cpte1 Is Not Null,[_BG_N2].Cpte1,[_BG_N3].Cpte1))) As Cpte1, \"\r\nRequete_SQL = Requete_SQL &amp; \"[_BG_N].Secteur, [_BG_N].P\u00e9rim\u00e8tre \"\r\nRequete_SQL = Requete_SQL &amp; \"FROM (((((\"\r\n'--- PLAN DE COMPTES AVEC LIBELLE DE COMPTE\r\nRequete_SQL = Requete_SQL &amp; \"SELECT [PLAN_COMPTES_COMPTES].CodeEntit\u00e9, [PLAN_COMPTES_COMPTES].CompteNum, [PLAN_COMPTES_COMPTES].Cpte3, \"\r\n'--- CompteLib\r\nRequete_SQL = Requete_SQL &amp; \"IIf([_BG_N].CompteLib Is Not Null,[_BG_N].CompteLib, \"\r\nRequete_SQL = Requete_SQL &amp; \"IIf([_BG_N1].CompteLib Is Not Null,[_BG_N1].CompteLib, \"\r\nRequete_SQL = Requete_SQL &amp; \"IIf([_BG_N2].CompteLib Is Not Null,[_BG_N2].CompteLib, \"\r\nRequete_SQL = Requete_SQL &amp; \"[_BG_N3].CompteLib))) AS CompteLib \"\r\n'--- PLAN_DE_COMPTES_COMPTES (CompteNum sans CompteLib)\r\nRequete_SQL = Requete_SQL &amp; \"FROM (((\"\r\n'---\r\nRequete_SQL = Requete_SQL &amp; \"(SELECT CodeEntit\u00e9, CompteNum, Cpte3 FROM (\"\r\nRequete_SQL = Requete_SQL &amp; \"SELECT CodeEntit\u00e9, CompteNum, Cpte3, Cpte1 FROM [\" &amp; CheminBDD &amp; BDD_N &amp; \"].[_BG] \"\r\nRequete_SQL = Requete_SQL &amp; \"UNION ALL \"\r\nRequete_SQL = Requete_SQL &amp; \"SELECT CodeEntit\u00e9, CompteNum, Cpte3, Cpte1 FROM [\" &amp; CheminBDD &amp; BDD_N1 &amp; \"].[_BG] \"\r\nRequete_SQL = Requete_SQL &amp; \"UNION ALL \"\r\nRequete_SQL = Requete_SQL &amp; \"SELECT CodeEntit\u00e9, CompteNum, Cpte3, Cpte1 FROM [\" &amp; CheminBDD &amp; BDD_N2 &amp; \"].[_BG] \"\r\nRequete_SQL = Requete_SQL &amp; \"UNION ALL \"\r\nRequete_SQL = Requete_SQL &amp; \"SELECT CodeEntit\u00e9, CompteNum, Cpte3, Cpte1 FROM [\" &amp; CheminBDD &amp; BDD_N3 &amp; \"].[_BG]) \"\r\n'--- CRITERES Cpte1 &lt;&gt;8 et 9\r\nRequete_SQL = Requete_SQL &amp; \"WHERE Cpte1&lt;&gt;\"\"9\"\" AND Cpte1&lt;&gt;\"\"8\"\" \"\r\n'--- REGROUPEMENT\r\nRequete_SQL = Requete_SQL &amp; \"GROUP BY CodeEntit\u00e9, CompteNum, Cpte3) As PLAN_COMPTES_COMPTES \"\r\n'------ LEFT JOIN\r\nRequete_SQL = Requete_SQL &amp; \"LEFT JOIN [\" &amp; CheminBDD &amp; BDD_N &amp; \"].[_BG] As [_BG_N] ON ([_BG_N].CompteNum = [PLAN_COMPTES_COMPTES].CompteNum) AND ([_BG_N].CodeEntit\u00e9 = [PLAN_COMPTES_COMPTES].CodeEntit\u00e9)) \"\r\nRequete_SQL = Requete_SQL &amp; \"LEFT JOIN [\" &amp; CheminBDD &amp; BDD_N1 &amp; \"].[_BG] As [_BG_N1] ON ([_BG_N1].CompteNum = [PLAN_COMPTES_COMPTES].CompteNum) AND ([_BG_N1].CodeEntit\u00e9 = [PLAN_COMPTES_COMPTES].CodeEntit\u00e9)) \"\r\nRequete_SQL = Requete_SQL &amp; \"LEFT JOIN [\" &amp; CheminBDD &amp; BDD_N2 &amp; \"].[_BG] As [_BG_N2] ON ([_BG_N2].CompteNum = [PLAN_COMPTES_COMPTES].CompteNum) AND ([_BG_N2].CodeEntit\u00e9 = [PLAN_COMPTES_COMPTES].CodeEntit\u00e9)) \"\r\nRequete_SQL = Requete_SQL &amp; \"LEFT JOIN [\" &amp; CheminBDD &amp; BDD_N3 &amp; \"].[_BG] As [_BG_N3] ON ([_BG_N3].CompteNum = [PLAN_COMPTES_COMPTES].CompteNum) AND ([_BG_N3].CodeEntit\u00e9 = [PLAN_COMPTES_COMPTES].CodeEntit\u00e9) \"\r\nRequete_SQL = Requete_SQL &amp; \") As PLAN_COMPTES \"\r\n'--- LEFT JOIN\r\nRequete_SQL = Requete_SQL &amp; \"LEFT JOIN [\" &amp; CheminBDD &amp; BDD_N &amp; \"].[_BG] As [_BG_N] ON ([_BG_N].CompteNum = [PLAN_COMPTES].CompteNum) AND ([_BG_N].CodeEntit\u00e9 = [PLAN_COMPTES].CodeEntit\u00e9)) \"\r\nRequete_SQL = Requete_SQL &amp; \"LEFT JOIN [\" &amp; CheminBDD &amp; BDD_N1 &amp; \"].[_BG] As [_BG_N1] ON ([_BG_N1].CompteNum = [PLAN_COMPTES].CompteNum) AND ([_BG_N1].CodeEntit\u00e9 = [PLAN_COMPTES].CodeEntit\u00e9)) \"\r\nRequete_SQL = Requete_SQL &amp; \"LEFT JOIN [\" &amp; CheminBDD &amp; BDD_N2 &amp; \"].[_BG] As [_BG_N2] ON ([_BG_N2].CompteNum = [PLAN_COMPTES].CompteNum) AND ([_BG_N2].CodeEntit\u00e9 = [PLAN_COMPTES].CodeEntit\u00e9)) \"\r\nRequete_SQL = Requete_SQL &amp; \"LEFT JOIN [\" &amp; CheminBDD &amp; BDD_N3 &amp; \"].[_BG] As [_BG_N3] ON ([_BG_N3].CompteNum = [PLAN_COMPTES].CompteNum) AND ([_BG_N3].CodeEntit\u00e9 = [PLAN_COMPTES].CodeEntit\u00e9)) \"\r\nRequete_SQL = Requete_SQL &amp; \"LEFT JOIN [\" &amp; CheminPAD &amp; BDD_PAD &amp; \"].[BG_Cycles] ON ([BG_Cycles].Cpte3 = [PLAN_COMPTES].Cpte3) \"\r\n'--- TRI DES BALANCES\r\nRequete_SQL = Requete_SQL &amp; \"ORDER BY [PLAN_COMPTES].CodeEntit\u00e9, [PLAN_COMPTES].CompteNum;\"<\/pre>\n<p style=\"text-align: justify;\">Comme quoi, il ne faut pas opposer les outils informatiques mais bien en tirer le meilleur de chacun en toute circonstance ;-).<\/p>\n<div id=\"sconnect-is-installed\" style=\"display: none;\">2.13.0.0<\/div>\n<div id=\"sconnect-is-installed\" style=\"display: none;\">2.13.0.0<\/div>\n<div style=\"padding-bottom:20px; padding-top:10px;\" class=\"hupso-share-buttons\"><!-- Hupso Share Buttons - https:\/\/www.hupso.com\/share\/ --><a class=\"hupso_counters\" href=\"https:\/\/www.hupso.com\/share\/\"><img decoding=\"async\" src=\"https:\/\/static.hupso.com\/share\/buttons\/lang\/fr\/share-small.png\" style=\"border:0px; padding-top:2px; float:left;\" alt=\"Share Button\"\/><\/a><script type=\"text\/javascript\">var hupso_services_c=new Array(\"twitter\",\"facebook_like\",\"facebook_send\",\"email\",\"print\",\"linkedin\");var hupso_counters_lang = \"fr_FR\";var hupso_image_folder_url = \"\";var hupso_twitter_via=\"BenoitRiviere14\";var hupso_url_c=\"\";var hupso_title_c=\"VBA%2FSQL%20vs%20Power%20Query%20%3A%20deux%20solutions%20compl%C3%A9mentaires\";<\/script><script type=\"text\/javascript\" src=\"https:\/\/static.hupso.com\/share\/js\/counters.js\"><\/script><!-- Hupso Share Buttons --><\/div>","protected":false},"excerpt":{"rendered":"<p>Power Query, module int\u00e9gr\u00e9 \u00e0 Excel, pr\u00e9pare les donn\u00e9es brutes (extraction, la transformation et le chargement ou ETL) en vue d&#8217;une analyse plus approfondie des donn\u00e9es dans Excel. Power Query a beaucoup d&#8217;adeptes (dont moi), notamment ceux qui pr\u00e9conisent le no-code. En effet, cet outil ne n\u00e9cessite pas de connaissance en programmation pour retraiter les &#8230;<\/p>\n<p><a href=\"https:\/\/www.auditsi.eu\/?p=12567\" class=\"more-link\">Continue reading &lsquo;VBA\/SQL vs Power Query : deux solutions compl\u00e9mentaires&rsquo; &raquo;<\/a><\/p>\n<div style=\"padding-bottom:20px; padding-top:10px;\" class=\"hupso-share-buttons\"><!-- Hupso Share Buttons - https:\/\/www.hupso.com\/share\/ --><a class=\"hupso_counters\" href=\"https:\/\/www.hupso.com\/share\/\"><img src=\"https:\/\/static.hupso.com\/share\/buttons\/lang\/fr\/share-small.png\" style=\"border:0px; padding-top:2px; float:left;\" alt=\"Share Button\"\/><\/a><script type=\"text\/javascript\">var hupso_services_c=new Array(\"twitter\",\"facebook_like\",\"facebook_send\",\"email\",\"print\",\"linkedin\");var hupso_counters_lang = \"fr_FR\";var hupso_image_folder_url = \"\";var hupso_twitter_via=\"BenoitRiviere14\";var hupso_url_c=\"\";var hupso_title_c=\"VBA%2FSQL%20vs%20Power%20Query%20%3A%20deux%20solutions%20compl%C3%A9mentaires\";<\/script><script type=\"text\/javascript\" src=\"https:\/\/static.hupso.com\/share\/js\/counters.js\"><\/script><!-- Hupso Share Buttons --><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[282,215],"tags":[173,2708,1643,1641],"class_list":["post-12567","post","type-post","status-publish","format-standard","hentry","category-sql","category-vba","tag-balance-generale","tag-power-query","tag-sql","tag-vba"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=\/wp\/v2\/posts\/12567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12567"}],"version-history":[{"count":3,"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=\/wp\/v2\/posts\/12567\/revisions"}],"predecessor-version":[{"id":12571,"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=\/wp\/v2\/posts\/12567\/revisions\/12571"}],"wp:attachment":[{"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auditsi.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}