Forum Discussion

jcru1999's avatar
jcru1999
Frequent Visitor
3 years ago
Solved

Automate Duplicate data sets in Power Query

Hi Community,  I hope you are doing well, I wanted to ask for some guidance. I work in HR and we are required to keep headcounts as of last day of the month. We can connect to the data source (Workd...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi, jcru1999 

    According to your description, your data comes from a URL, and you need to modify the fixed parameters of the URL every time you get the data.
    If you want to automate, I think you can define the way you get the data in Power Query as a custom function.

    The parameter passed in is your date, and then you create a date column at the end of the month.

    The end of month's date column you can use this M code(put this in the "Advanced Editor"):

    let
        Source = List.Distinct(List.Transform(List.Dates(#date(2023,1,1), Duration.Days(Duration.From(#date(2023,12,31)-#date(2023,1,1))) +1, #duration(1, 0, 0, 0))
    ,(x)=> Date.EndOfMonth(x))),
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}})
    in
        #"Changed Type"

    Then you can use "Add custom column."
    And pass in this [Column1] column to call the Custom Column you wrote to return your data row by row.

     

    For more information, you can refer to this:
    How to use Power Query Custom Functions (exceloffthegrid.com)

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly