Forum Discussion

THEG72's avatar
THEG72
Helper V
7 years ago
Solved

Calculated Column with numeric field and text field

I have the following table data and would like to make  a custom column that will have 2 possible outputs "Cash Inflow" or "Cash Outflow" as shown in the formula required section below.

 

There are two groups of transactions as shown in the FinanceGroup. Some inflows are positive so there are revenue items and some and negative representing selling costs. The same scenario on the outflows side but again a positive is an outflow and negative is a refund or return of cashflow costs.

 

What is the best method to achieve this result efficiently using a M custom column?

 

What is the correct method to first reference the Text field in the finance group and then work out if the value is positive or negative so the amount can be correctly classified? 

 

I used this code below, but just looking to see what is best method.

 

if [FinanceGroup] = "Revenue" and [Value] > 0 then "Cash Inflow"
else if [FinanceGroup] = "Revenue" and [Value] < 0 then "Cash Outlfow"
else if [FinanceGroup] = "Costs" and [Value] > 0 then "Cash Outlfow"
else if [FinanceGroup] = "Costs" and [Value] < 0 then "Cash Inflow" else "Nil Cashflow"

 

  • Hi,

    This M code works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Finance Group", type text}, {"Value", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Finance Group]="Revenue" then if [Value]>0 then "Cash Inflow" else "Cash Outflow" else if [Value]<0 then "Cash Outflow" else "Cash Inflow")
    in
        #"Added Custom"

    Hope this helps.

9 Replies

  • ChandeepChhabra's avatar
    ChandeepChhabra
    Impactful Individual

    THEG72 You can use DAX or M

    Please refer to the Excel file for both solutions

     

     

    Two quick things

    1. The label "cost" is written in 2 different ways, I have provided for that in DAX and M
    2. Please note that power query is case sensitive and DAX is not

    Thanks

     

  • Hi,

    This M code works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Finance Group", type text}, {"Value", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Finance Group]="Revenue" then if [Value]>0 then "Cash Inflow" else "Cash Outflow" else if [Value]<0 then "Cash Outflow" else "Cash Inflow")
    in
        #"Added Custom"

    Hope this helps.