cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
THEG72 Member
Member

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"

 

Test.PNG

2 ACCEPTED SOLUTIONS

Accepted Solutions
ChandeepChhabra Established Member
Established Member

Re: Calculated Column with numeric field and text field

@THEG72 If my reply helped, could you mark it as a solution?

 

thanks

View solution in original post

Highlighted
Super User IV
Super User IV

Re: Calculated Column with numeric field and text field

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.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
ChandeepChhabra Established Member
Established Member

Re: Calculated Column with numeric field and text field

@THEG72 You can use DAX or M

Please refer to the Excel file for both solutions

 

Capture.png

 

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

 

THEG72 Member
Member

Re: Calculated Column with numeric field and text field

@ChandeepChhabra 

thanks there is a mistake there is only two codes Revenue or Costs.

 

ChandeepChhabra Established Member
Established Member

Re: Calculated Column with numeric field and text field

@THEG72 If my reply helped, could you mark it as a solution?

 

thanks

View solution in original post

Highlighted
Super User IV
Super User IV

Re: Calculated Column with numeric field and text field

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.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

THEG72 Member
Member

Re: Calculated Column with numeric field and text field

@Ashish_Mathur  thanks for your M code, what happens if the value is zero? how would you code account for that?

THEG72 Member
Member

Re: Calculated Column with numeric field and text field

@ChandeepChhabra  Can you switch statement handle a zero value too ?

Super User IV
Super User IV

Re: Calculated Column with numeric field and text field

What would you want the result to be?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ChandeepChhabra Established Member
Established Member

Re: Calculated Column with numeric field and text field

@THEG72 No it can't for now. What label do you want in-case it is a zero?

THEG72 Member
Member

Re: Calculated Column with numeric field and text field

@ChandeepChhabra  I guess this is more for error logic and accounting for all the possibilities of the values. you could output "No Cashflow"

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors