Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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"
Solved! Go to Solution.
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.
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.
@Ashish_Mathur thanks for your M code, what happens if the value is zero? how would you code account for that?
What would you want the result to be?
@THEG72 You can use DAX or M
Please refer to the Excel file for both solutions
Two quick things
Thanks
@ChandeepChhabra I guess this is more for error logic and accounting for all the possibilities of the values. you could output "No Cashflow"
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
65 |
User | Count |
---|---|
136 | |
118 | |
101 | |
71 | |
61 |