Forum Discussion

ovetteabejuela's avatar
ovetteabejuela
Impactful Individual
9 years ago
Solved

PowerQuery: Extract Date Into Column | Challenge

Hi Community,

 

EDIT: Hi MarcelBeug, do you think this is doable? What I'm thinking is to

1. duplicate that column (The one with UNIT ID header)

2. Remove other values other than 

>= 03/01/2017 and < 03/02/2017

3. Clean further with final result 03/01/2017

4. Fill Down.

 

I'm stuck at Step 2 though...

 

I need some help getting this Date into a Field:

 

This is how raw data looks like(see desired output just below this one):

Report Name:Some_Report_Name  
Site:Some_Site  
Indicator:All  
Report Period:>= 03/01/2017 and < 03/02/2017  
EmployeeUnit IDMetric 1Metric 2
Mraw, Dwana90777500
Mraw, Dwana90777500
Mraw, Dwana90777500
Mraw, Dwana90777500
Makara, Laurena9090141594
Makara, Laurena90901400
Makara, Laurena9090142707
Makara, Laurena90901400
Kokko, Thurman1295855141175
Spartz, Bradley128548411103
Spartz, Bradley128548400
Spartz, Bradley128548451479
Spartz, Bradley128548400
Setaro, Jerlene129659821616
Erne, Frankie120279100
Erne, Frankie120279100
Erne, Frankie120279114523
Erne, Frankie120279100
Gavell, Elvera129659723599
Langstraat, Miesha43509900
Langstraat, Miesha43509900
Langstraat, Miesha43509938511
Langstraat, Miesha43509900
Kanis, Kerri12714071548
Kanis, Kerri127140700
Kanis, Kerri127140723739
Kanis, Kerri127140700

 

Here's the Desired Output:

EmployeeUnit IDMetric 1Metric 2Date
Mraw, Dwana907775003/1/2017
Mraw, Dwana907775003/1/2017
Mraw, Dwana907775003/1/2017
Mraw, Dwana907775003/1/2017
Makara, Laurena90901415943/1/2017
Makara, Laurena909014003/1/2017
Makara, Laurena90901427073/1/2017
Makara, Laurena909014003/1/2017
Kokko, Thurman12958551411753/1/2017
Spartz, Bradley1285484111033/1/2017
Spartz, Bradley1285484003/1/2017
Spartz, Bradley1285484514793/1/2017
Spartz, Bradley1285484003/1/2017
Setaro, Jerlene1296598216163/1/2017
Erne, Frankie1202791003/1/2017
Erne, Frankie1202791003/1/2017
Erne, Frankie1202791145233/1/2017
Erne, Frankie1202791003/1/2017
Gavell, Elvera1296597235993/1/2017
Langstraat, Miesha435099003/1/2017
Langstraat, Miesha435099003/1/2017
Langstraat, Miesha435099385113/1/2017
Langstraat, Miesha435099003/1/2017
Kanis, Kerri127140715483/1/2017
Kanis, Kerri1271407003/1/2017
Kanis, Kerri1271407237393/1/2017
Kanis, Kerri1271407003/1/2017
  • My approach would be to get the Date, remove rows, promote headers, add a column with the Date and have data types detected (Select all columns - Transform tab - Detect data type).

     

    let
        Source = Table1,
        Date = Text.Trim(Text.BetweenDelimiters(Source{3}[Column2],">=", "and")),
        #"Removed Top Rows" = Table.Skip(Source,4),
        #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
        #"Added Custom" = Table.AddColumn(#"Promoted Headers", "Date", each Date),
        #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Employee", type text}, {"Unit ID", Int64.Type}, {"Metric 1", Int64.Type}, {"Metric 2", Int64.Type}, {"Date", type date}})
    in
        #"Changed Type"

     

9 Replies

  • MarcelBeug's avatar
    MarcelBeug
    Community Champion

    My approach would be to get the Date, remove rows, promote headers, add a column with the Date and have data types detected (Select all columns - Transform tab - Detect data type).

     

    let
        Source = Table1,
        Date = Text.Trim(Text.BetweenDelimiters(Source{3}[Column2],">=", "and")),
        #"Removed Top Rows" = Table.Skip(Source,4),
        #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
        #"Added Custom" = Table.AddColumn(#"Promoted Headers", "Date", each Date),
        #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Employee", type text}, {"Unit ID", Int64.Type}, {"Metric 1", Int64.Type}, {"Metric 2", Int64.Type}, {"Date", type date}})
    in
        #"Changed Type"

     

    • ovetteabejuela's avatar
      ovetteabejuela
      Impactful Individual

      Your simply awesome!

       

      I'm trying to understand this though:

       

      Source{3}[Column2]

      Source{3} >>> is that 4th row (0-based index)?

      • MarcelBeug's avatar
        MarcelBeug
        Community Champion

        Yes, You get this if you right-click the value and choose Drill Down: