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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
JMesquitaFilho
Regular Visitor

Create Custom Column in Power Query (M language) from DAX Formula

I need to create a custom column, in power query (M language), using a formula developed in DAX language, as follows:

ValorAtual =
VAR ultimoipca =
    CALCULATE ( VALUES ( Ipca[Valor] ), TOPN ( 1, Ipca, Ipca[Data], DESC ) )
RETURN
    ROUND ( DIVIDE ( 'ReD'[Valor] * ultimoipca, [IpcaSoma] ), 2 )

'ReD'[Valor] - is a column of present table (ReD table)

Ipca[Valor] , Ipca[Data] and [IpcaSoma] - from other table (Ipca table)

 

Can someone help me please?

1 ACCEPTED SOLUTION

Hi @JMesquitaFilho 

 

What is the [IpcaSoma] in your DAX? Is it a measure or something else? I don't see this data in your screenshots of two tables. If possible, you can use some natural language and the sample data to explain what you want to calculate in the custom column. This could help us understand the expected result better. 

 

Assume you already have a [IpcaSoma] column in ReD table, you can add two steps to get the custom column. 

Step #1: Add a custom step to get the latest value from Ipca table

Step #2: Create the required custom step 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrS0tNA31Dc2VNJRcgFiXRNDUz1DYyDL0MDAQClWB1VJEBCbmxrApWMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t, CodNat = _t, Valor = _t, IpcaSoma = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type date}, {"CodNat", type text}, {"Valor", type number}, {"IpcaSoma", Int64.Type}}),
    
    // Add a custom step to get the latest value from Ipca table
    ultimoipca = Table.First(Table.Sort(Ipca, {"Data", Order.Descending}))[Valor],
    // Add a custom column 
    #"Added Custom" = Table.AddColumn(#"Changed Type", "ValorAtual", each Number.Round([Valor] * ultimoipca / [IpcaSoma], 2), type number)
in
    #"Added Custom"

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

4 REPLIES 4
serpiva64
Solution Sage
Solution Sage

Hi,

it's much easier if you provide some sample data

Hi, serpiva64.

In the table below (ReD) I want to create the custom column:

JMesquitaFilho_1-1675520978141.png

The table below (Ipca) contains the information I will use to update data from the ReD table:

JMesquitaFilho_2-1675521269381.png

The formula for the update is as follows (in DAX language):

ValorAtual =
VAR ultimoipca =
    CALCULATE ( VALUES ( Ipca[Valor] ), TOPN ( 1IpcaIpca[Data]DESC ) )
RETURN
    ROUND ( DIVIDE ( 'ReD'[Valor] * ultimoipca[IpcaSoma] ), 2 )
 
Thanks for your attention.

 

 

Hi @JMesquitaFilho 

 

What is the [IpcaSoma] in your DAX? Is it a measure or something else? I don't see this data in your screenshots of two tables. If possible, you can use some natural language and the sample data to explain what you want to calculate in the custom column. This could help us understand the expected result better. 

 

Assume you already have a [IpcaSoma] column in ReD table, you can add two steps to get the custom column. 

Step #1: Add a custom step to get the latest value from Ipca table

Step #2: Create the required custom step 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrS0tNA31Dc2VNJRcgFiXRNDUz1DYyDL0MDAQClWB1VJEBCbmxrApWMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t, CodNat = _t, Valor = _t, IpcaSoma = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type date}, {"CodNat", type text}, {"Valor", type number}, {"IpcaSoma", Int64.Type}}),
    
    // Add a custom step to get the latest value from Ipca table
    ultimoipca = Table.First(Table.Sort(Ipca, {"Data", Order.Descending}))[Valor],
    // Add a custom column 
    #"Added Custom" = Table.AddColumn(#"Changed Type", "ValorAtual", each Number.Round([Valor] * ultimoipca / [IpcaSoma], 2), type number)
in
    #"Added Custom"

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Thank you very much, @v-jingzhang.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.