Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
rafavillegas
Frequent Visitor

New Custom Column in power query with the last month of data

Hello Forum!

I have this table in power query:

rafavillegas_1-1702088716643.png

 

 

And I would a conditional table to read last month with data and copy amount value in the new column, see below the answer

rafavillegas_3-1702088775167.png

 


Thank you so much in advance.



1 ACCEPTED SOLUTION
spinfuzer
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtM3MtY3MjAyVtJRMjQwMFCK1YlWstQ3tIAJmsIEzfWNTJFVwpXCBM3BYrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Amount", Int64.Type}}),
    add_last_month =
        let last_month = Date.StartOfMonth(List.Max(#"Changed Type"[Date]))
        in Table.AddColumn(#"Changed Type", "Last Month Cost", each if [Date] < last_month then null else [Amount], type number)
in
    add_last_month

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

Hi @rafavillegas ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
spinfuzer
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtM3MtY3MjAyVtJRMjQwMFCK1YlWstQ3tIAJmsIEzfWNTJFVwpXCBM3BYrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Amount", Int64.Type}}),
    add_last_month =
        let last_month = Date.StartOfMonth(List.Max(#"Changed Type"[Date]))
        in Table.AddColumn(#"Changed Type", "Last Month Cost", each if [Date] < last_month then null else [Amount], type number)
in
    add_last_month
Ashish_Mathur
Super User
Super User

Hi,

Why should the answer be 5000 and 7000?  Also, why not create a calculated column formula in DAX?  Why are you trying to do this in Power Query?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Because I create a report with the cost to date and with the cost in the last month.

And I need it in Power query instead of DAX, because later this column has relationships with another column of other data, and with Dax doesn't work right.

Relationships are created in the Data model (not in Power Query) so we can create a calculated column formula.  I still do not understand how you arived at 5000 and 7000 in column 3.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.