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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Rockz
New Member

How to use custom column in power query using a measure logic.

Dear Champions,

 

Iam using a measure as below

VAR D7 = CALCULATE(SUM(histories[actual]), histories[name] = "Total Cost")*-1

VAR E7 = CALCULATE(SUM(histories[commitment]), histories[name] = "Total Cost")*-1

VAR C7 = CALCULATE(SUM(histories[total]), histories[name] = "TotalCost")*-1

RETURN D7+E7-C7

I want same logic to be implemented in power query custom column. I tried in all the ways but not able to achieve it, please help me to implement and achieve this!!

Thanks in advance!

 

1 ACCEPTED SOLUTION
v-tianyich-msft
Community Support
Community Support

Hi @Rockz ,

 

There seems to be a slight problem with the data you provided, I created simple samples and you can check the results below:

vtianyichmsft_0-1716366419194.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMgWTFmCyJL8kMUchOb+4RClWJ1rJCCxoAiYtwaRvYgVC2hgsZIREIuuPBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Actual = _t, Commitment = _t, total = _t, name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Actual", Int64.Type}, {"Commitment", Int64.Type}, {"total", Int64.Type}, {"name", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom.1", each if [name] = "total cost" then [Actual] + [Commitment] - [total] else null),
    #"Renamed Columns" = Table.RenameColumns(#"Added Custom",{{"Custom.1", "Final"}})
in
    #"Renamed Columns"

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-tianyich-msft
Community Support
Community Support

Hi @Rockz ,

 

There seems to be a slight problem with the data you provided, I created simple samples and you can check the results below:

vtianyichmsft_0-1716366419194.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMgWTFmCyJL8kMUchOb+4RClWJ1rJCCxoAiYtwaRvYgVC2hgsZIREIuuPBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Actual = _t, Commitment = _t, total = _t, name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Actual", Int64.Type}, {"Commitment", Int64.Type}, {"total", Int64.Type}, {"name", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom.1", each if [name] = "total cost" then [Actual] + [Commitment] - [total] else null),
    #"Renamed Columns" = Table.RenameColumns(#"Added Custom",{{"Custom.1", "Final"}})
in
    #"Renamed Columns"

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

ROCKZZ
Regular Visitor

Dear Tom,

This is the sample data and your assumption is correct. 

ActualCommitmenttotalDatename
1.4511.121345710-05-2024Total cost
1.33.33.335 90.88111-05-2024Miniam cost
   12-05-2024Max cost
 20.019 13-05-2024Total cost
-16.673  14-05-2024avg cost
11.1112239223415-05-2024Total cost
2.88.9991.2341345616-05-2024minaiml cost
34.44.44.45642.098-917317-05-2024max cost
19.17.2833.19.98212.34018-05-2024Total cost
 11.2231.29.08319-05-2024avg cost
19.90.1839.08110.97320-05-2024Total cost
1.09.87319.0821.39.08321-05-2024cost
33.3302.34.59.0811.50.09722-05-2024Total cost
13467291.81918.90323-05-2024avg cost
1.23.45610.98223.00.98224-05-2024max cost
2.00119.0831.09725-05-2024minimal cost
13.00.9122.0972.22.35626-05-2024Total cost
2.07.78323.90823.99027-05-2024Total cost
2.22.0292422.99.81728-05-2024Total cost

Thanks for helping!

TomMartens
Super User
Super User

Hey @Rockz ,

 

Please provide sample data that represents your table "histories." Make sure that the sample data also contains a column showing the expected result.

I assume you want the SUMmed value (D7+E7-C7) repeats for each of the rows, is this assumption correct?

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.