it is possible to make a custom column if statement that calculates values of certain cells in another column in power query ?

bleeet

Board Regular
Joined
May 11, 2009
Messages
208
Office Version
  1. 2013
Platform
  1. Windows
Sorry guys

This is hard for me to explain in the title but I asking if it's possible to mimic this excel if statement formula

Code:
=IF(OR(AND(J2<>J1, T2<>0), AND(J2=J1, AND(T2<>0,T1=0))),1,"")

in a custom column in power query? If so how can I do it?


thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi
Let your table is Table1 and its columns as J1 and T1
Code:
let
    source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    typed = Table.TransformColumnTypes(source,{{"J1", Int64.Type}, {"T1", Int64.Type}}),
    indexed = Table.AddIndexColumn(typed, "id", 1),
    renamed = Table.RenameColumns(typed, { {"J1", "J2"}, {"T1", "T2"} }),
    indexed2 = Table.AddIndexColumn(renamed, "id2", 0),
    joined = Table.Join(indexed, {"id"}, indexed2, {"id2"}),
    calced = Table.AddColumn(joined, "calced", each if [J1] <> [J2] and [T2] <> 0 or [J1] = [J2] and [T2] <> 0 and [T1] = 0 then 1 else null, type nullable number)
in
    calced[[J1], [T1], [J2], [T2], [calced]]
Regards,
 
Upvote 0
Hi
Let your table is Table1 and its columns as J1 and T1
Code:
let
    source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    typed = Table.TransformColumnTypes(source,{{"J1", Int64.Type}, {"T1", Int64.Type}}),
    indexed = Table.AddIndexColumn(typed, "id", 1),
    renamed = Table.RenameColumns(typed, { {"J1", "J2"}, {"T1", "T2"} }),
    indexed2 = Table.AddIndexColumn(renamed, "id2", 0),
    joined = Table.Join(indexed, {"id"}, indexed2, {"id2"}),
    calced = Table.AddColumn(joined, "calced", each if [J1] <> [J2] and [T2] <> 0 or [J1] = [J2] and [T2] <> 0 and [T1] = 0 then 1 else null, type nullable number)
in
    calced[[J1], [T1], [J2], [T2], [calced]]
Regards,


yikes not working for me

I think I can simplify my request how can I flag each name in a table as a "1"

for example my table sort of like this but with more data columns in between these

100datajoedee
100datajoedee
500datasallywoo
300datasmithkay
300datasmithkay

<tbody>
</tbody>

I want to do a head count by marking "1" in a another column beside each name. the name might be mentioned in a few rows under it but I don't want those rows marked as "1" only the first row where the name is mentioned like this.

100datajoedee1
100datajoedee
500datasallywoo1
300datasmithkay1
300datasmithkay

<tbody>
</tbody>

I hope this makes sense.


thanks
 
Upvote 0
Hi
No problem. Let colum names of Table1 are F1, F2, F3, F4.
Code:
let
    source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    typed = Table.TransformColumnTypes(source,{{"F1", Int64.Type}, {"F2", type text}, {"F3", type text}, {"F4", type text}}),
    grouped = Table.Group(typed, {"F1", "F2", "F3", "F4"}, {{"group", each Table.AddIndexColumn(_, "id", 1), type table}}),
    expanded = Table.ExpandTableColumn(grouped[[group]], "group", {"F1", "F2", "F3", "F4", "id"}),
    return = Table.TransformColumns(expanded, { {"id", each if _ = 1 then 1 else null, type nullable number}})
in
    return
Regards,
 
Upvote 0
Try this...
A​
B​
C​
D​
E​
9​
100datajoedee1
10​
100datajoedee
11​
500datasallywoo1
12​
300datasmithkay1
13​
300datasmithkay
E9=IF(COUNTIFS($B$9:B9,B9,$C$9:C9,C9,$D$9:D9,D9)>1,"",1)
copied down
 
Upvote 0
Hi, FDibbins!
Do you have any test of your formula in the Power Query? It is a branch about Power BI:LOL:
 
Last edited:
Upvote 0
Hi
No problem. Let colum names of Table1 are F1, F2, F3, F4.
Code:
let
    source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    typed = Table.TransformColumnTypes(source,{{"F1", Int64.Type}, {"F2", type text}, {"F3", type text}, {"F4", type text}}),
    grouped = Table.Group(typed, {"F1", "F2", "F3", "F4"}, {{"group", each Table.AddIndexColumn(_, "id", 1), type table}}),
    expanded = Table.ExpandTableColumn(grouped[[group]], "group", {"F1", "F2", "F3", "F4", "id"}),
    return = Table.TransformColumns(expanded, { {"id", each if _ = 1 then 1 else null, type nullable number}})
in
    return
Regards,


Hi Anvg

sorry I am new to power query and it seems I am probably putting the code in the wrong place. Where do I put it? do I make a new table?
 
Upvote 0

Forum statistics

Threads
1,214,790
Messages
6,121,607
Members
449,037
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top