Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have a table like
Table_Test =
DATATABLE
(
"name" , STRING ,
"Status" , STRING ,
"price" , INTEGER ,
"cost" , INTEGER ,
{
{"A", "sold", 200, 100},
{"A", "onHand", 200, 100},
{"B","sold", 300, 150},
{"B","onHand", 300,150}
}
)
Total cash = IF( [Status] = "sold", SUM([price]), SUMX(Table_Test, [cost] * -1) )
of course, it can not work since [status] is not in row-context.
And I do not want to new a column like this:
cash = IF([Status] = "sold", [price], [cost]*-1)
Solved! Go to Solution.
@Anonymous , if they are from one table
sumx(Table_Test,IF( Table_Test[Status] = "sold", (Table_Test[price]), Table_Test[cost] * -1 ) )
Hi @Anonymous
try
sumx( Table_Test,
IF( Table_Test[Status] = "onHand",
Table_Test[cost] * -1,
IF(Table_Test[price] > 0, [price], 0)
)
)
@Anonymous , if they are from one table
sumx(Table_Test,IF( Table_Test[Status] = "sold", (Table_Test[price]), Table_Test[cost] * -1 ) )
thanks you!!!
how about if I want to consider cost but ignore price if it is negetive when do sum, for example
Table_Test =
DATATABLE
(
"name" , STRING ,
"Status" , STRING ,
"price" , INTEGER ,
"cost" , INTEGER ,
{
{"A", "sold", 200, 100},
{"A", "onHand", 200, 100},
{"B","sold", 300, 150},
{"B","onHand", 300,150},
{"oil20200426", "won'tsold", -50, 100}
}
)
how to realiza something like
sumx( Table_Test,
IF( Table_Test[Status] = "onHand",
Table_Test[cost] * -1,
Table_Test[price] when [price] is positive)
)
)?
Hi @Anonymous
try
sumx( Table_Test,
IF( Table_Test[Status] = "onHand",
Table_Test[cost] * -1,
IF(Table_Test[price] > 0, [price], 0)
)
)
You can use the FILTER function instead.
Something like:
Total cash = SUMX(FILTER(Table_Test, Table_Test[Status]= "sold"), Table_Test[price]) - SUMX(FILTER(Table_Test, Table_Test[status]<>"sold"),Table_Test[cost])
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
https://sites.google.com/site/allisonkennedycv
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
99 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
87 | |
64 |