Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ANM_97
Helper IV
Helper IV

DECREASE THE VALUE AND ADD THE VALUE ACCORDING TO CATEGORY

Hi!

I have the following situation: I have 3 categories (A, B ,C) , their value and loss. I have to DEDUCT the loss from category A AND ADD IT TO category C.

 

EXAMPLE:

 CATEGORY VALUELOSS
 A 10020
 B 1200
 C 500
 TOTAL 27020

 

EXPECTED RESULT:

 

 CATEGORY VALUELOSS
 A 800
 B 1200
 C 7020
 TOTAL 27020

WHAT MEASURE COULD I BUILD?

 

THANKS! ~~

 

1 ACCEPTED SOLUTION
vanessafvg
Super User
Super User

try this.
 
result_test =
var VALA = CALCULATE(sum(Test[LOSS]), FILTER(ALLSELECTED(Test),Test[CATEGORY] ="A"))
return
IF(SELECTEDVALUE(Test[CATEGORY]) = "A", SUM(Test[VALUE]) - SUM(Test[LOSS]),
if(SELECTEDVALUE(Test[CATEGORY]) = "C", sum(Test[VALUE]) + VALA,
sum(Test[VALUE])))




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




View solution in original post

10 REPLIES 10
vanessafvg
Super User
Super User

try this.
 
result_test =
var VALA = CALCULATE(sum(Test[LOSS]), FILTER(ALLSELECTED(Test),Test[CATEGORY] ="A"))
return
IF(SELECTEDVALUE(Test[CATEGORY]) = "A", SUM(Test[VALUE]) - SUM(Test[LOSS]),
if(SELECTEDVALUE(Test[CATEGORY]) = "C", sum(Test[VALUE]) + VALA,
sum(Test[VALUE])))




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Thank you for help! 🙂

vanessafvg
Super User
Super User

LossC=
var lossA = CALCULATE(sum('Table'[LOSS]), 'Table'[CATEGORY] = "A")
var valC = CALCULATE(sum('Table'[VALUE]), 'Table'[CATEGORY] = "C")
return valC + lossA
 
lossA=
var lossA = CALCULATE(sum('Table'[LOSS]), 'Table'[CATEGORY] = "A")
var valA = CALCULATE(sum('Table'[VALUE]), 'Table'[CATEGORY] = "A")
return valA - lossA




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Tahreem24
Super User
Super User

@ANM_97 , Need to create measures like this:

NEW VALUE  = SUM(Table[Value])-SUM(Table[Loss])

NEW LOSS = 0 

OR NEW LOSS MEASURE = SUM(Table[Loss])-SUM(Table[Loss])

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

@Tahreem24 

It's not that simple. The value of LOSS = 20 must be subtracted from A and added to category C. I have attached a measure, but it does not add to category C.

 

ANM_97_1-1616759032445.png

 

vanessafvg
Super User
Super User

depends on how you want to use it

 

result  = sum('Table'[VALUE]) - sum('Table'[LOSS])

RESULT 2 = SUMX ( table, 'table'[value] - 'table'[loss] )





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@vanessafvg 

It's not that simple. The value of LOSS = 20 must be subtracted from A and added to category C. I have attached a measure, but it does not add to category C.

ANM_97_0-1616759006894.png

 

I try this: 

ANM_97_0-1616760487206.png

But don't work ok, because the LOSS value is also low from the total value.

 

I am not sure why you are asking for someone else to come and help when I am putting my time into helping you?    Please provide the code  you have used in text form so i can see what is going on





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




I appreciate the time you give. With the solution sent by you, I did not get the expected result. It would help me if you tested the measure before answering. I tried many options. This is the measure from the picture:
 
 
result_test =
VAR lossA = CALCULATE( sum(test[LOSS]), test[CATEGORY] = "A")
VAR valC = CALCULATE( sum(test[VALUE]), test[CATEGORY] = "B")
return
IF(FIRSTNONBLANK(test[CATEGORY],"") ="A", CALCULATE(SUM(test[VALUE]) - lossA),
IF(FIRSTNONBLANK(test[CATEGORY], "") ="C", CALCULATE(valC + lossA), SUM(test[VALUE])))

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.