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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
zhandos
Frequent Visitor

Excel formulas in Power Query

Dear community,

 

Can you please help me to get column "B" results inside Power Query? Formulas are written in Excel

 

 BCformula
20 0
30 B2
410000 (B5-B3)/2+B3
52000020000B3+C5
620000 B5
726000 (B8-B6)/2+B6
83200012000B6+C8
1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @zhandos ,

 

I've done this purely as an exercise, but I don't imagine this will be of any use to you in reality. Paste this over the default code in a new blank query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUTIAYqVYnWglY2SOCZBhbmAA55sCGYYGEAFDEAMsagbimSIpMwcyLJD4FiAFRhABS7CuWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}}),
    addCalcs = Table.AddColumn(chgTypes, "calcs", each 
let
  B2 = chgTypes{0}[B],
  B3 = chgTypes{1}[B],
  B4 = chgTypes{2}[B],
  B5 = chgTypes{3}[B],
  B6 = chgTypes{4}[B],
  B7 = chgTypes{5}[B],
  B8 = chgTypes{6}[B],
  C5 = chgTypes{3}[C],
  C8 = chgTypes{6}[C]
in

if [A] = 2 then 0
else if [A] = 3 then B2
else if [A] = 4 then (B5-B3)/2+B3
else if [A] = 5 then B3+C5
else if [A] = 6 then B5
else if [A] = 7 then (B8-B6)/2+B6
else if [A] = 8 then B6+C8
else null)
in
    addCalcs

 

 

This is not what Power Query is designed for, you should be using DAX on a properly-structured table for these types of calculations.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

1 REPLY 1
BA_Pete
Super User
Super User

Hi @zhandos ,

 

I've done this purely as an exercise, but I don't imagine this will be of any use to you in reality. Paste this over the default code in a new blank query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUTIAYqVYnWglY2SOCZBhbmAA55sCGYYGEAFDEAMsagbimSIpMwcyLJD4FiAFRhABS7CuWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}}),
    addCalcs = Table.AddColumn(chgTypes, "calcs", each 
let
  B2 = chgTypes{0}[B],
  B3 = chgTypes{1}[B],
  B4 = chgTypes{2}[B],
  B5 = chgTypes{3}[B],
  B6 = chgTypes{4}[B],
  B7 = chgTypes{5}[B],
  B8 = chgTypes{6}[B],
  C5 = chgTypes{3}[C],
  C8 = chgTypes{6}[C]
in

if [A] = 2 then 0
else if [A] = 3 then B2
else if [A] = 4 then (B5-B3)/2+B3
else if [A] = 5 then B3+C5
else if [A] = 6 then B5
else if [A] = 7 then (B8-B6)/2+B6
else if [A] = 8 then B6+C8
else null)
in
    addCalcs

 

 

This is not what Power Query is designed for, you should be using DAX on a properly-structured table for these types of calculations.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors