Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

add conditional column

Hello!

I have this table. Relevant for us are the columns [Nummer], [Saldo] and [Date].

 

For each Month there is 1 row in [nummer]. I just want to add a column [saldo previous month] where it takes the corresponding value from [saldo] from the same [nummer] from last month.

 

I've made an example in the picture below.

 

Can somebody help me to add this conditional column? I really don't get it how to code this column. 

Thank you!

Marco

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

    1. add a custom column like:

    2. merge queries:

    3. expand and rename [Saldo] column:

        #"Added Custom" = Table.AddColumn(#"Umbenannte Spalten", "Custom", each Date.AddMonths([Date],-1)),
        #"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Nummer", "Custom"}, #"Added Custom", {"Nummer", "Date"}, "Sorted Rows", JoinKind.LeftOuter),
        #"Expanded Sorted Rows" = Table.ExpandTableColumn(#"Merged Queries", "Sorted Rows", {"Saldo"}, {"Saldo.1"}),
        #"Removed Columns" = Table.RemoveColumns(#"Expanded Sorted Rows",{"Custom"}),
        #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Saldo.1", "saldo previous month"}})
    in
        #"Renamed Columns"

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data

7 Replies

  • I think this would be better served by a DAX Measure. And [Nummer] is strictly a dimension of your data.

    • marcobi's avatar
      marcobi
      Helper I

      i did it with dateadd:

      Saldo Last Month = CALCULATE(SUM(ER_und_Bilanz[Saldo]),VALUES(ER_und_Bilanz[Nummer]),DATEADD(ER_und_Bilanz[Date],-1,MONTH))

       

      But I'm working with a slicer, and then the month before must also be selected that it works. thats why i thought a want to add a column where the data from last month is already inside. so i only have to select one month

       
  • negi007's avatar
    negi007
    Community Champion

    Anonymous can you share your sample pbix file

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous ,

        1. add a custom column like:

        2. merge queries:

        3. expand and rename [Saldo] column:

            #"Added Custom" = Table.AddColumn(#"Umbenannte Spalten", "Custom", each Date.AddMonths([Date],-1)),
            #"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Nummer", "Custom"}, #"Added Custom", {"Nummer", "Date"}, "Sorted Rows", JoinKind.LeftOuter),
            #"Expanded Sorted Rows" = Table.ExpandTableColumn(#"Merged Queries", "Sorted Rows", {"Saldo"}, {"Saldo.1"}),
            #"Removed Columns" = Table.RemoveColumns(#"Expanded Sorted Rows",{"Custom"}),
            #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Saldo.1", "saldo previous month"}})
        in
            #"Renamed Columns"

        Best Regards,
        Gao

        Community Support Team

         

        If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

        How to get your questions answered quickly -- How to provide sample data