Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Listwise multiplication in power query query

https://1drv.ms/x/c/7b02b2fed748fc63/ETzmzZMX2lJJl7G89fFRfyoBmaLUsZ_cX1TCog6kPPWZ4A Hi
All values ​​in certain columns in the table I obtained from the power query query
I want to multiply a list by period titles.

(inflation table above x all values ​​below)

If there is a way to do this, both in the query and in the pivot table result, I would like you to help me.

 

 2024/92024/62024/32023/122023/92023/62023/32022/122022/92022/62022/32022/42022/52022/522022/532022/542022/552022/562022/572022/582022/592022/602022/612024/92024/62024/32023/122023/92023/62023/32022/122022/92022/62022/32022/42022/52022/522022/532022/542022/552022/562022/572022/582022/592022/602022/61all to the right
                            1,00                    1,09                    1,18                      1,36                    1,49                    1,87                    1,99                      2,24                    1,00                    1,00                    1,00                      1,00                    1,00                    1,00                    1,00                      1,00                    1,00                    1,00                    1,00                      1,00                    1,00                    1,00                    1,00                                              1,00                    1,09                    1,18                      1,36                    1,49                    1,87                    1,99                      2,24                    1,00                    1,00                    1,00                      1,00                    1,00                    1,00                    1,00                      1,00                    1,00                    1,00                    1,00                      1,00                    1,00                    1,00                    1,00 
 Sütun Etiketleri                                              
 1A                      1AA                      1AB
 Dönen Varlıklar                        Nakit ve Nakit Benzerleri                        Finansal Yatırımlar
 CURRENT ASSETS                      Cash and Cash Equivalents                      Short-Term Financial Investments
Satır EtiketleriToplam 2024/9Toplam 2024/6Toplam 2024/3Toplam 2023/12Toplam 2023/9Toplam 2023/6Toplam 2023/3Toplam 2022/12Toplam 2022/9Toplam 2022/6Toplam 2022/3Toplam 2021/12Toplam 2021/9Toplam 2021/6Toplam 2021/3Toplam 2020/12Toplam 2020/9Toplam 2020/6Toplam 2020/3Toplam 2019/12Toplam 2019/9Toplam 2019/6Toplam 2019/3Toplam 2024/9Toplam 2024/6Toplam 2024/3Toplam 2023/12Toplam 2023/9Toplam 2023/6Toplam 2023/3Toplam 2022/12Toplam 2022/9Toplam 2022/6Toplam 2022/3Toplam 2021/12Toplam 2021/9Toplam 2021/6Toplam 2021/3Toplam 2020/12Toplam 2020/9Toplam 2020/6Toplam 2020/3Toplam 2019/12Toplam 2019/9Toplam 2019/6Toplam 2019/3Toplam 2024/9
AFYON179944699312978290941201121800170827124695154144178120485063973039711609240066776765764595367933172005051964728591542229831340595231460524471364704201070107589596041571924552665284315867954372357068769768208174383373427417333719421554602640691667871861304711357535179845283589623434729110308430986038995187683214627001309952466627793235000414850683114569652221185704011218576907232106798070
ASTOR19384400220156160702841472637170517708532409997753848881374136446869505689852832266544926128730024988976470  1142626133   837685327   3929684347291062084816893790792285825725123434369619340001871565859895235805647212890419002930962820  224697347   94004816   2780886140
CIMSA27922996000134065910001169607700016420159000724936700067524450005949882000149454770005775581388398615458229272871162239831068198693613817311678852207271551255690157014969572731335612520171017327510866476701085041480109788436898552637919867165000570308100050605730008568258000160259700019100110002206681000691157500020022255366467555513727270772579118034409948265656924013550696739039617524170352974157316557563194542673505432398893931767037771447336130
  • lbendlin's avatar
    lbendlin
    1 year ago

    you already have the data in the right format. All you need to do is NOT to do the last step.

     

    Don't do the "PivotedColumns"  step, and all will be good.  You can then join your table with the inflation table

     

    based on the Period.

     

     

     

     

6 Replies

  • As usual when you transition from Excel to Power BI, the first thing you need to do is unpivot your data to bring it into a usable format.  After that you can decide if you even want to do the calculations in Power Query, or if it is simpler and faster to do them in Power BI.

     

     

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUjDUMzBQUNIBMyyhDEMLKMPYDMowgUlZmEMZlhARIz0jE5h2g4FmxMYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"2024/9" = _t, #"2024/6" = _t, #"2024/3" = _t, #"2023/12" = _t, #"2023/9" = _t, #"2023/6" = _t, #"2023/3" = _t, #"2022/12" = _t, #"2022/9" = _t, #"2022/6" = _t, #"2022/3" = _t, #"2021/12" = _t, #"2021/9" = _t, #"2021/6" = _t, #"2021/3" = _t, #"2020/12" = _t, #"2020/9" = _t, #"2020/6" = _t, #"2020/3" = _t, #"2019/12" = _t, #"2019/9" = _t, #"2019/6" = _t, #"2019/3" = _t]),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {}, "Month", "Value"),
        #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Columns",{{"Value", type number}})
    in
        #"Changed Type"

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    hi

    Thank you for your answer.


    I don't use Power BI.

    Taking it out of the pivot table and reintroducing it into the process would cause me to do a lot of extra work, like a vicious cycle.

    It would be better to do this during the power query before the pivot table result.


    I think this is what your code does
    "
    Source = Excel.CurrentWorkbook(){[Name="inflation"]}[Content],
    #"PivotColumnsResolved" = Table.UnpivotOtherColumns(Source, {}, "Property", "Value"),
    "

    But the next thing I need help with is:
    It is the multiplication of the inflation coefficient under the period by all values ​​corresponding to the same period.

     

    let
    rate = Excel.CurrentWorkbook(){[Name="inflation"]}[Content],
    
        // Sembollerin alınması ve filtrelenmesi
        tblSymbols = Excel.CurrentWorkbook(){[Name="tblSymbols_Sector"]}[Content],
        RenamedColumns = Table.RenameColumns(tblSymbols, {{"Column1", "Symbol"}}),
        FilteredSymbols = Table.SelectRows(RenamedColumns, each [Symbol] <> null),
        // Sütun türlerinin değiştirilmesi
        ChangedType = Table.TransformColumnTypes(FilteredSymbols, {{"Symbol", type text}}),
        // Taban URL'lerin eklenmesi ve genişletilmesi
        BaseURLs = Excel.CurrentWorkbook(){[Name="tblFinansal_URLs"]}[Content],
        GetBaseURL = Table.AddColumn(ChangedType, "BasedURL", each BaseURLs),
        ExpandedBasedURL = Table.ExpandTableColumn(GetBaseURL, "BasedURL", {"URL"}, {"URL"}),
        // Sembollerin URL'ye eklenmesi ve verilerin alınması
        ReplacedSymbol = Table.AddColumn(ExpandedBasedURL, "ReplaceSYMBOL", each Text.Replace([URL], "SYMBOL", [Symbol])),
        GetSourceValue = Table.AddColumn(ReplacedSymbol, "GetData", each Table.FromList(Json.Document(Web.Contents([ReplaceSYMBOL]))[value], Splitter.SplitByNothing(), null, null, ExtraValues.Error)),
        // Verilerin genişletilmesi
        ExpandedGetData = Table.ExpandTableColumn(GetSourceValue, "GetData", {"Column1"}, {"Column1"}),
        ExpandedColumn = Table.ExpandRecordColumn(ExpandedGetData, "Column1", {"itemCode", "itemDescTr", "itemDescEng", "value1", "value2", "value3", "value4"}, {"itemCode", "itemDescTr", "itemDescEng", "value1", "value2", "value3", "value4"}),
        // Seçilen sütunların unpivot edilmesi
        UnpivotedColumns = Table.Unpivot(ExpandedColumn, {"value1", "value2", "value3", "value4"}, "ValueNo", "Value"),
        // URL'den dönem bilgisi alınması
        GetPdFromURL = Table.AddColumn(UnpivotedColumns, "GetPeriodFromURL", each Text.AfterDelimiter([URL], "&year"), type text),
        SplitColumn = Table.SplitColumn(GetPdFromURL, "GetPeriodFromURL", Splitter.SplitTextByDelimiter("&year", QuoteStyle.None)),
        // Dönem sütunlarının unpivot edilmesi
        UnpivotedPeriodColumns = Table.Unpivot(SplitColumn, List.Select(Table.ColumnNames(SplitColumn), each Text.StartsWith(_, "GetPeriodFromURL.")), "Attribute", "TempPd"),
        // Dönem bilgisine göre özel sütun eklenmesi
        AddedCustom = Table.AddColumn(UnpivotedPeriodColumns, "Period", each if Text.End([ValueNo], 1) = Text.Start([TempPd], 1) then Text.Replace(Text.End(Text.Start([TempPd], Text.PositionOfAny([TempPd], {"&"}, Occurrence.First)), 4) & "/" & Text.End([TempPd], Text.Length([TempPd]) - Text.PositionOfAny([TempPd], {"="}, Occurrence.Last) - 1), "&", "") else null),
        // Null değerlerin filtrelenmesi
        FilteredRows = Table.SelectRows(AddedCustom, each ([Period] <> null) and ([TempPd] <> "")),
        // Gereksiz sütunların kaldırılması
        RemovedColumns = Table.RemoveColumns(FilteredRows, {"URL", "ReplaceSYMBOL", "ValueNo", "Attribute", "TempPd"}),
        // Sütun türlerinin yeniden değiştirilmesi
        ChangedTypeFinal = Table.TransformColumnTypes(RemovedColumns, {{"Value", Int64.Type}}),
        // Pivot işlemi
        PivotedColumn = Table.Pivot(ChangedTypeFinal, List.Distinct(ChangedTypeFinal[Period]), "Period", "Value")
    in
        PivotedColumn

    DNZ.xlsx

    • lbendlin's avatar
      lbendlin
      Super User

      As I said I would unpivot both tables. Then group by Satır Etiketleri  , then List.Zip the values with the inflation multiplier.

  • Anonymous's avatar
    Anonymous
    Not applicable

    hi

    I couldn't understand how this had anything to do with what I wanted.
    I don't use "power bi".
    Can this operation be done in "power query"? If so, how.
    The sample excel file is there.
    Thank you.

    • lbendlin's avatar
      lbendlin
      Super User

      you already have the data in the right format. All you need to do is NOT to do the last step.

       

      Don't do the "PivotedColumns"  step, and all will be good.  You can then join your table with the inflation table

       

      based on the Period.

       

       

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    The action I want is
    It was more complex than that and was in interrogation.
    However, I realized that the transaction I wanted could not be solved this way.
    Thank you for your answer and efforts.