Dynamic Unpivoting in Power Query

Поділитися
Вставка
  • Опубліковано 26 сер 2024

КОМЕНТАРІ • 67

  • @wayneedmondson1065
    @wayneedmondson1065 3 роки тому +7

    Hey Chandeep.. inspired by your lesson, came up with the following to have definitive control over the columns to unpivot:
    1. Make a second data table and name it: ColumnsToUnpivot; in the table, enter the exact column names that you want to unpivot (in your example: Jan, Feb, etc); load as connection only; convert to a list
    2. Load Table1 as connection only; make a Reference to Table1 and rename it: Table1Ref
    3. In Table1Ref do the formula: = Table.ColumnNames(Table1); convert to Table
    4. Add Custom Column with formula: = Table.AddColumn(#"Converted to Table", "Custom", each List.Contains(ColumnsToUnpivot,[Column1])); filter for FALSE; drill down on Column1; rename as ColumnNames
    5. Add step with: = Table1
    6. Unpivot step with: = Table.UnpivotOtherColumns(Custom1, ColumnNames, "Month", "Value"); close and load to new or existing sheet
    I learned that referencing the Table1 query is necessary to avoid the dreaded Formula.Firewall error. Loading a specific list of column names that you want to unpivot puts you in complete control of the outcome, no matter what other columns are inserted into the original data table. List.Contains() does the magic to allow you to filter to exactly what you want from your specified list of column names. This was a great learning experience for me, inspired by your video lesson. So, thought I would share it back for anyone interested. Thanks again for all your great videos and resource. I always learn something new at Goodly :)) Thumbs up!!

  • @markdixon333
    @markdixon333 Рік тому +3

    Awesome - EXACTLY what i needed to learn how to do. Many thanks Chandeep

  • @zuzanasmekalova4632
    @zuzanasmekalova4632 3 місяці тому

    you are a genius, exactly what I was looking for!

  • @damionc
    @damionc 2 роки тому

    Like wow. I learn something new on all your videos. You are the boss.

  • @tak0331
    @tak0331 Рік тому

    Just used this for the first time - simple and effective. Another tool in the arsenal. Thank you Chandeep!

  • @pondyanand
    @pondyanand 2 роки тому

    Excellent video ! Thanks Chandeep. Very useful.

  • @zahir585
    @zahir585 Рік тому

    Nothing but the best my friend, good job 🙌🏻

  • @teaking1981
    @teaking1981 2 роки тому +1

    I was working through this query as part of my learning, using the same logic as the video or instead finding columns to unpivot you can do it in one step using list select, you can access the has error field if you wrap your logical test in brackets and use the field access operator, so the result returns true or false, which in list select true will select the item here is the part of the code:
    List Select
    List Argument Table Column Names
    Selection condition each ( try Date From ) [ Has Error ]
    That should get you all the columns that dont convert to a date or with not all the columns that do in one step, then just use the result in unpivot columns

  • @marksimmonds4818
    @marksimmonds4818 3 місяці тому

    Good stuff in this one!

  • @kashifkhanspecial
    @kashifkhanspecial 3 роки тому +1

    Hi Chandeep! Thank you so much for this knowledgeable tutorial, I learned a lot to watch this tutorial.
    Please take good care of yourself & your family, stay safe & healthy.
    Take care
    Thanks
    Kashif

  • @fimko1
    @fimko1 3 роки тому +1

    So simple! And so useful!

  • @eslamfahmy87
    @eslamfahmy87 11 місяців тому

    Great, as usual 👏

  • @KgasS
    @KgasS Рік тому

    Thanks. The following code also works with few steps
    let
    Source = Excel.CurrentWorkbook(){[Name="PivotedTable"]}[Content], // Get the Table content
    /* Pivot criteria is to keep only the month columns
    Table column names are tested to convert them to type date if fails that is not included in the column names */
    PivotCriteria = List.Select(Table.ColumnNames(Source), each try Value.Type(Date.FromText("2002/"& _ &"/01"))=type date otherwise false),
    UnpivotedTable = Table.Unpivot(Source, PivotCriteria, "Month", "Qty")
    in
    UnpivotedTable

  • @vinod71234
    @vinod71234 3 роки тому

    Ajj ayuga beere suwaad bhut din ho gye matha marde nu....esse problem t

  • @mailravikumar1981
    @mailravikumar1981 3 роки тому

    Thanks a lot, this video helped me to solve my problem :)

  • @CideeTV
    @CideeTV Рік тому

    thank you for this sharing..really appreciate it.

  • @wayneedmondson1065
    @wayneedmondson1065 3 роки тому +1

    Hi Chandeep. Awesome post! Love tricks to make procedures dynamic and I've wondered how to solve this exact problem. Thanks for sharing the technique. Will definitely use it in the future in my work :)) Thumbs up!!

    • @GoodlyChandeep
      @GoodlyChandeep  3 роки тому +1

      Thanks Wayne! Glad you found it helpful.

  • @aahanavikram07
    @aahanavikram07 3 роки тому

    Learning query through your video is quite simple.
    Thanks for making it very easy to understand.

  • @wildecorrea6477
    @wildecorrea6477 3 роки тому +1

    Awesome!!!

  • @IvanCortinas_ES
    @IvanCortinas_ES 3 роки тому

    Tremendous solution! Thank you Chandeep!

  • @seb1000
    @seb1000 3 роки тому

    very helpful, thanks

  • @bharathau8085
    @bharathau8085 4 місяці тому

    It was great !😊

  • @thebhaskarjoshi
    @thebhaskarjoshi 2 роки тому

    Thank you so much for this knowledgeable tutorial

  • @winbin82
    @winbin82 3 роки тому

    Thank !! Thank !!

  • @BestICan
    @BestICan 3 роки тому

    Excellent.

  • @nishantkumar9570
    @nishantkumar9570 3 роки тому

    Very interesting....

  • @IlaPatel811
    @IlaPatel811 2 роки тому

    Love this!! Thanks!:)

  • @mohammadraiesh4648
    @mohammadraiesh4648 11 місяців тому

    Very nice 🎉❤

  • @baderalzuraiq9968
    @baderalzuraiq9968 3 роки тому

    Excellent solution!!

  • @ExactProBi
    @ExactProBi 3 роки тому

    amazing!

  • @maheshtorgal
    @maheshtorgal 3 роки тому

    Hey Chandeep,
    Thank you for your all videos, I've learnt lot.
    Actually I am looking for your help as I am creating a rental database of rental properties where we are paying rents to landlords. So below are some agreement details where I wanted to create a monthly Rent statement that to be paid to landlord
    Example -
    - Landlord Name - ABC
    - Agreement Period- 15 Aug 19 to 14 Aug 25
    - Initial rent : 1000
    - Escalation after 3 year : 15%
    - So after 3 year, rent will be - 1150
    Output should be as per below:
    Sr No From To Rent
    1 15 Aug 19 31 Aug 19 =1000/31x17 = 548.38
    2 1 Sep 19 30 Sep 19 1000
    3 1 Oct 19 31 Oct 19 1000
    ...
    ...
    36 1 Aug 22 31 Aug 22 = [1000/31x14] + [1150/31x17]= 1082.25
    37 1Sep 22 30 Sep 22 1150
    ...
    ...
    61 1 Aug 15 14 Aug 25 =1150/31x14 = 519.35

  • @juja2819
    @juja2819 2 роки тому

    Thank you! :)

  • @joebateman9668
    @joebateman9668 3 роки тому

    Really interesting solution!

  • @mnowako
    @mnowako 3 роки тому

    Excellent! Thank you! 👏

  • @kennethstephani692
    @kennethstephani692 3 роки тому

    Great video!

  • @umakanta7
    @umakanta7 3 роки тому

    Thanks for the tutorial.I have query like how we can make the other columns (jan-dec) dynamic?My unpivot columns are from current month till X month.

  • @paragkhandalkar
    @paragkhandalkar 3 роки тому

    How can we create patterns if the columns is lets say some measures which are other than dates or months?

  • @18hourscold87
    @18hourscold87 7 місяців тому

    i unpivot a selected columns to be use as lookup column for merge concatenated col query. after getting the result of that selected column how can i unpivot that one column to become a header adjacent to the right column.

  • @Sri-Nivas
    @Sri-Nivas 3 роки тому

    Great tutorial Chandeep.. 👍💐

  • @sanjeevsoni6793
    @sanjeevsoni6793 3 роки тому

    Excellent job 👏👍👌

  • @khalidmajeed2886
    @khalidmajeed2886 2 роки тому

    if we add column after brand .....

  • @danishnawaz3651
    @danishnawaz3651 2 роки тому

    If the following code works with but if we replace with = it does not works ..Why ?
    (List.Select(Table.ColumnNames(#"Removed Columns"), each _ "Item Name" and _ "Color" )
    List.Select(Table.ColumnNames(#"Removed Columns"), each _ = "Item Name" and _ = "Color" )
    (Refe.. Video . (Dynamic Unpivoting in Power Query)

  • @FRANKWHITE1996
    @FRANKWHITE1996 3 роки тому

    Great video as always thank you

  • @rrrraaaacccc80
    @rrrraaaacccc80 Рік тому

    💯👍

  • @hussainmeghani4809
    @hussainmeghani4809 3 роки тому

    How to adjust source file path or dynamically adj path where my working and source file placed...so when i share the file to someone then power query function properly ... pls advised

  • @vijayvizzu1
    @vijayvizzu1 3 роки тому

    Chandeep, great video, i have an doubt, what if the column names are renamed like Jan Forecast becomes Jan Actual, here Jan is going to use to get the Date by which calendar table is linked. When we manually changes, the power query will given an error while refreshing. Do you have any suggestion to tackle this issue ?

    • @wayneedmondson1065
      @wayneedmondson1065 3 роки тому

      Hey Vijay. See above my post for this solution. In short, you add another table as connection only with the specific column names you want to unpivot. Then you use List.Contains to filter the matches for the list that gets used in the Table.UnpivotOtherColumns step. The only complication is that Power Query does not like it when you refer to a Source made from a step inside the same Source. So, you have to trick it by landing the Source in one query and then referencing it as the Source for the second query where you actually perform the steps. Maybe Chandeep will to a video on this. Hope my comments help you. Good luck!

  • @marshal115
    @marshal115 3 роки тому

    How about this unpivoting in a single statement?
    = Table.UnpivotOtherColumns(Source, List.FirstN(Table.ColumnNames(Source), each _ "Jan"), "Month", "Value")

  • @GoodlyChandeep
    @GoodlyChandeep  9 місяців тому

    Check out our newly launched M Language course ↗ - goodly.co.in/learn-m-powerquery/