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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Bassil74
Helper I
Helper I

Add conditions to run different part of the PQ code

I have this part of my script that i need to make it run different parts of the code based on the language:

let
    Language = "En",
    //Language = "Fr",
    //Language = "Sp",
    .
    .
    .
  If Language = "En" then run this part
      Expandmeasurement = Table.ExpandRecordColumn(Table.ExpandListColumn(MergeColumns, "measurements"), "measurements", { "Reached", "monitoringPeriodId,""CumulativeReach"}, {"Reached", "monitoringPeriodId","CumulativeReach"}),
    ReorderColumns = Table.ReorderColumns(WithMp_Number,{"monitoringPeriodId", "Reached", "CumulativeReach"}),
 elsif 
Language = "Fr" then run this part
      Expandmeasurement = Table.ExpandRecordColumn(Table.ExpandListColumn(MergeColumns, "measurements"), "measurements", { "Atteints", "monitoringPeriodId","Cumulatteints"}, {"attent", "monitoringPeriodId","Cumulatteints"}),
    ReorderColumns = Table.ReorderColumns(WithMp_Number,{"monitoringPeriodId", "Atteints", "Cumulatteints"}),
elsif 
Language = "SP" then run this part
      Expandmeasurement = Table.ExpandRecordColumn(Table.ExpandListColumn(MergeColumns, "measurements"), "measurements", { "Atendidas", "monitoringPeriodId","Alcance cumulativo"}, {"Atendidas", "monitoringPeriodId","Alcance cumulativo"}),
    ReorderColumns = Table.ReorderColumns(WithMp_Number,{"monitoringPeriodId", "Atendidas", "Alcance cumulativo"}),
in
ReorderColumns

Apprecaite any ideas about it, thank you

4 REPLIES 4
Bassil74
Helper I
Helper I

To clarify, i want a script that branch logic to  implement scertain parts:

 

I need help to include a condition in my steps for the below part: 

 

    Language = "En",
    //Language = "Fr",
    //Language = "Sp",
 
  If Language "En" then      Expandmeasurement = Table.ExpandRecordColumn(Table.ExpandListColumn(MergeColumns, "measurements"), "measurements", { "Reached", "monitoringPeriodId,""CumulativeReach"}, {"Reached", "monitoringPeriodId","CumulativeReach"}),
    ReorderColumns = Table.ReorderColumns(WithMp_Number,{"monitoringPeriodId""Reached""CumulativeReach"}),
 els if 
Language "Fr" then run this part
      Expandmeasurement = Table.ExpandRecordColumn(Table.ExpandListColumn(MergeColumns"measurements"), "measurements", { "Atteints""monitoringPeriodId","Cumulatteints"}, {"attent""monitoringPeriodId","Cumulatteints"}),
    ReorderColumns = Table.ReorderColumns(WithMp_Number,{"monitoringPeriodId""Atteints""Cumulatteints"}),
els if 
Language "Sp" then run this part
      Expandmeasurement = Table.ExpandRecordColumn(Table.ExpandListColumn(MergeColumns"measurements"), "measurements", { "Atendidas""monitoringPeriodId","Alcance cumulativo"}, {"Atendidas""monitoringPeriodId","Alcance cumulativo"}),
    ReorderColumns = Table.ReorderColumns(WithMp_Number,{"monitoringPeriodId""Atendidas""Alcance cumulativo"}),
in
Expandmeasurement 

Thank you,

 

 your code results in different column names which will trigger a meta data update, and is generally considered to be a bad thing. Would be better if you would keep the column names constant and carry the language choice through as a separate column.
lbendlin
Super User
Super User

replace "elsif"  with "else if"  and you should be good.

 

or you could refactor the code and move the checks inside the list.

 

However your code results in different column names which will trigger a meta data update, and is generally considered to be a bad thing. Would be better if you would keep the column names constant and carry the language choice through as a separate column.

 

 

THank you @lbendlin . The data is fetched from an API which has columns values stored in three languages, i.e. "Reached", "Atteints", "Atendidas". Iam now rethinking it, to store these values in a separate table i.e. measurementsLanguages

Language      | Value1       |  Value2

En                  | Reached    | CumulativeReach

Fr                  | Atteints      Cumulatteints

 

and use them based on the language selected.

let

    Language = "En",
    //Language = "Atteints",
    //Language = "Atendidas",
 
 If Language "En" then run this part
     Expandmeasurement = Table.ExpandRecordColumn(Table.ExpandListColumn(MergeColumns"measurements"), "measurements", { "Reached""monitoringPeriodId,""CumulativeReach"}, {measurementsLanguages[Value1]"monitoringPeriodId",measurementsLanguages[Value2]}),
    ReorderColumns = Table.ReorderColumns(WithMp_Number,{"monitoringPeriodId""Reached""CumulativeReach"}),
...etc

But this didn't wok as it assume measurementsLanguages is the datasource and is not fetching the column names. Do you have any better way of doing it?    

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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