Malcoolm
Malcoolm

Reputation: 478

Power Query functions : best way to import another data format in same table?

I have a data set that I import in PowerBI using PowerQuery and calling a function to transform my binary into a table.

My original data set consist in daily Excel files that I transform slightly.

Recently I've stumbled across a legacy database of the same data but arranged differently and I'd like to import it in the same table (there is a full year of data in a single file).

I was wondering what is the cleanest way to conditionally call my function:

I don't see the option to do that, I only see conditional columns but not conditional function calls in my PowerBI desktop.

Thanks !

Upvotes: 0

Views: 1072

Answers (1)

msta42a
msta42a

Reputation: 3741

I don't know how you invoke your function, but you can manipulate transformation by modifying M code in Advanced Editor. Create two steps as independent flow in my example #"Added Custom" and #"Added Customv2";

here example, try this code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWJVjKCs4yBLCcwywTOMgWynMEsMzjLHKIjFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DayOfWeek = _t, Duty = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DayOfWeek", Int64.Type}, {"Duty", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each "ALLShift"),
    #"Added Customv2" = Table.AddColumn(#"Changed Type", "Custom", each "MorningShift"),
    #"EndStep" = if Date.Month(DateTime.LocalNow()) = 9 then #"Added Custom" else #"Added Customv2"
in
    #"EndStep"

Check EndStep

#"EndStep" = if Date.Month(DateTime.LocalNow()) = 9 then #"Added Custom" else #"Added Customv2"

As you see, depending on current month I show in output #"Added Customv2" or #"Added Custom". You can in this same way change your source based on some if conditions.

Upvotes: 1

Related Questions