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
gssarathkumar
Helper I
Helper I

Power Query Transformation Request - Power Bi Request

I have  a below table as data source, which needs to be transformed as below:

Input:

S.NoCategoryNameInput1Input2KPITargetDeviation
1Category1Name1ActivityCurrent progress to date    
   100%85%15.00%5%10.00% 
         
2Category2Name2Planned ActivityDeveloped so far    
   252392.00%100%8.00% 
         
3Category3Name3Future PlansAccepted Plans    
   2020100.00%95%-5.00% 
         
4Category4Name4Required SkillsActual Skills    
   100%10%10.00%90.0%80.00% 
         

 

Required Output:

S.NoCategoryNameInput1Input1 ValueInput2Input2 ValueKPITargetDeviation
1Category1Name1Activity100%Current progress to date85%15.00%5%10.00% 
2Category2Name2Planned Activity25Developed so far2392.00%100.00%8.00% 
3Category3Name3Future Plans20Accepted Plans20100.00%95%-5.00% 
4Category4Name4Required Skills100%Actual Skills10%100.00%90.0%80.00% 

 

Can someone please help me on this? The challenge that I am facing is the input is in first row and input value is in anothe row and also there is an empty column between each line items.

 

@amitchandak , @Greg_Deckler @lbendlin , @DesktopOwl @Goodlytics4U @Anonymous 

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

pls try this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZFNC8IwDIb/Shl4m9J9gR5F8Siix7FD0SjDus6uHezfm2ydVlARQt68TUsfkjwPoiAMVsLARemO6q24AenyaMq2NB21rdZQGVZrddHQNMwodsIn2HJRhHnwdBHnE5R5RjnKZoMdHO/d2/W3oE7sEcWOiHQnRVXBiXlka2hBqhoPG8XOQn8hijNKCaZF7HBGyD94Eo8ncTykG2usBkZYTT+wI9QGUcaDjyR8TAjgUBb9aKbZHyiph5I6FNI93G2p8e/DtZRyoDFWyJf/saiIe6tBHCz60bhdFQ8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [S.No = _t, Category = _t, Name = _t, Input1 = _t, Input2 = _t, KPI = _t, Target = _t, Deviation = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"S.No", Int64.Type}, {"Category", type text}, {"Name", type text}, {"Input1", type text}, {"Input2", type text}, {"KPI", type text}, {"Target", type text}, {"Deviation", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"S.No", "Category", "Name", "Input1", "Input2", "KPI", "Target", "Deviation"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"S.No", "Category", "Name"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Input1] <> null)),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Filtered Rows", {"S.No", "Category", "Name"}, "Attribute", "Value"),
    #"Replaced Value1" = Table.ReplaceValue(#"Unpivoted Other Columns",each [Attribute],each if Text.Contains([Attribute],"input", Comparer.OrdinalIgnoreCase) and  Value.Is(Number.From(Text.Replace([Value],"%","")), Number.Type) then [Attribute]&" Value" else [Attribute] ,Replacer.ReplaceText,{"Attribute", "Value"}),
    #"Pivoted Column" = Table.Pivot(#"Replaced Value1", List.Distinct(#"Replaced Value1"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

View solution in original post

4 REPLIES 4
gssarathkumar
Helper I
Helper I

Hello All,

I got the required output, thanks for your support. However, there is a concern here.
The table contains two different data types. 1, Percentage and 2, Number.
After the table is transformed, I am not able to get the values with desired data type. Either I am getting in All Percentage values or All Number values. Is there a way for fixing this issue and use the values as in the source. Note: I need these values to be used for calculation in DAX.

 

@amitchandak , @Greg_Deckler @lbendlin , @DesktopOwl @Goodlytics4U @help Ahmedx @Ahmedx @lbendlin 

Ahmedx
Super User
Super User

pls try this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZFNC8IwDIb/Shl4m9J9gR5F8Siix7FD0SjDus6uHezfm2ydVlARQt68TUsfkjwPoiAMVsLARemO6q24AenyaMq2NB21rdZQGVZrddHQNMwodsIn2HJRhHnwdBHnE5R5RjnKZoMdHO/d2/W3oE7sEcWOiHQnRVXBiXlka2hBqhoPG8XOQn8hijNKCaZF7HBGyD94Eo8ncTykG2usBkZYTT+wI9QGUcaDjyR8TAjgUBb9aKbZHyiph5I6FNI93G2p8e/DtZRyoDFWyJf/saiIe6tBHCz60bhdFQ8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [S.No = _t, Category = _t, Name = _t, Input1 = _t, Input2 = _t, KPI = _t, Target = _t, Deviation = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"S.No", Int64.Type}, {"Category", type text}, {"Name", type text}, {"Input1", type text}, {"Input2", type text}, {"KPI", type text}, {"Target", type text}, {"Deviation", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"S.No", "Category", "Name", "Input1", "Input2", "KPI", "Target", "Deviation"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"S.No", "Category", "Name"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Input1] <> null)),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Filtered Rows", {"S.No", "Category", "Name"}, "Attribute", "Value"),
    #"Replaced Value1" = Table.ReplaceValue(#"Unpivoted Other Columns",each [Attribute],each if Text.Contains([Attribute],"input", Comparer.OrdinalIgnoreCase) and  Value.Is(Number.From(Text.Replace([Value],"%","")), Number.Type) then [Attribute]&" Value" else [Attribute] ,Replacer.ReplaceText,{"Attribute", "Value"}),
    #"Pivoted Column" = Table.Pivot(#"Replaced Value1", List.Distinct(#"Replaced Value1"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

Generally speaking your data is not in a usable format.

 

Anyway, here's another approach:

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "ldHNCsIwDADgVykDb1O6P3BHUTyK6HHsUDTKsK6zawXf3mTrtChMPDRp+gMfSVEEURAGS2HgrPSD9htxBcqLg6nulXnQtdUaasMarc4a2pYZxY74Ba/Ya5Vh4VVhEHE+wTTPKEbZrC/7infV54/vRS9izxc7H+WtFHUNR+Y5V3AHqRo8bBU7CT3qizMKCYY8driB/Icu8XSJ01FeW2M1MEK2XTMP0BiEDQcjLj4E5DhY3rVtmv0BSz1Y6mCUd3CzlUbJ/lJJ2duMFfJd/xxpxL0hIg43XdvcVMsn",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [
        S.No = _t,
        Category = _t,
        Name = _t,
        Input1 = _t,
        Input2 = _t,
        KPI = _t,
        Target = _t,
        Deviation = _t
      ]
  ),
  #"Filtered Rows" = Table.SelectRows(Source, each ([Input1] <> " ")),
  #"Replaced Value" = Table.ReplaceValue(
    #"Filtered Rows",
    " ",
    null,
    Replacer.ReplaceValue,
    {"S.No"}
  ),
  #"Filled Down" = Table.FillDown(#"Replaced Value", {"S.No"}),
  #"Merged Queries" = Table.NestedJoin(
    Table.SelectColumns(
      Table.SelectRows(#"Filled Down", each ([Category] <> " ")),
      {"S.No", "Category", "Name", "Input1", "Input2"}
    ),
    {"S.No"},
    Table.SelectColumns(
      Table.SelectRows(#"Filled Down", each ([KPI] <> " ")),
      {"S.No", "Input1", "Input2", "KPI", "Target", "Deviation"}
    ),
    {"S.No"},
    "Removed Other Columns",
    JoinKind.LeftOuter
  ),
  #"Expanded Removed Other Columns" = Table.ExpandTableColumn(
    #"Merged Queries",
    "Removed Other Columns",
    {"Input1", "Input2", "KPI", "Target", "Deviation"},
    {"Input1 Value", "Input2 Value", "KPI", "Target", "Deviation"}
  ),
  #"Reordered Columns" = Table.ReorderColumns(
    #"Expanded Removed Other Columns",
    {
      "S.No",
      "Category",
      "Name",
      "Input1",
      "Input1 Value",
      "Input2",
      "Input2 Value",
      "KPI",
      "Target",
      "Deviation"
    }
  )
in
  #"Reordered Columns"

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.