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

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.

Reply
Anonymous
Not applicable

To create measure/column to calculate value based on multiple conditions of other columns

Hi,

 

I am stuck at this problem to calculate sum based on multiple condition. I have this weekly table. I want to create a measure or calculated  column - if the sum of value contributed for variable group "base" is less than 0 then sum the values of value contributed column where the variable group is not "base". Divide each variable group value contributed with the sum of 

value contributed where the variable group is not "base". If it's greater than 0 then copy the value of value contributed column value as it is. Here's an example- for week 10-feb-2020 the sum of value contributed column for variable group "base" is -26 (50-157+81) which is less than 0 so, I want to create a column highlighted where the formula should be  77/(77+40+1)*actual value = (77/118)*91 = 59.3

spsingh_0-1661807401263.png

 

 

For this week 13-Apr-20, the sum of value contributed for base is greater than 0 so, I just want to copy the value of value contributed column as it is.

spsingh_2-1661808314871.png

 

Table example-

 

weekvaluevariablesvariable group pred valueactual valueproportion of valuevalue contributedmeasure/column
10-Feb-2054febbase99910.55500
10-Feb-20-170compbase9991-1.73-1570
10-Feb-2083aoffline99910.8577(77/(77+40+1))*91
10-Feb-2044bonline99910.4440(40/(77+40+1))*91
10-Feb-201coffline99910.011(1/(77+40+1))*91
10-Feb-2087interceptbase99910.89810
10-Feb-200doffline9991000
10-Feb-200eonline9991000
10-Feb-200fonline9991000
10-Feb-200gonline9991000
10-Feb-200honline9991000
10-Feb-200ibase9991000
10-Feb-200decbase9991000
10-Feb-200augbase9991000
10-Feb-200novbase9991000
10-Feb-200maybase9991000
10-Feb-200janbase9991000
10-Feb-200octbase9991000
10-Feb-200sepbase9991000
10-Feb-200julbase9991000
10-Feb-200junbase9991000
10-Feb-200aprbase9991000
13-Apr-20193aprbase2794400.69304304
13-Apr-2055covbase2794400.28686
13-Apr-20-181compbase279440-0.65-286-286
13-Apr-2091aoffline2794400.33144144
13-Apr-2028bonline2794400.14444
13-Apr-206coffline2794400.021010
13-Apr-2087interceptbase2794400.31138138
13-Apr-200doffline279440000
13-Apr-200eonline279440000
13-Apr-200fonline279440000
13-Apr-200gonline279440000
13-Apr-200honline279440000
13-Apr-200decbase279440000
13-Apr-200augbase279440000
13-Apr-200novbase279440000
13-Apr-200maybase279440000
13-Apr-200janbase279440000
13-Apr-200octbase279440000
13-Apr-200sepbase279440000
13-Apr-200julbase279440000
13-Apr-200junbase279440000
13-Apr-200febbase279440000

 

I hope the question is clear if not please let me know.

Any help would be much appreciated.

1 ACCEPTED SOLUTION
Adescrit
Impactful Individual
Impactful Individual

Hi @Anonymous 

 

How about the formula below:

 

Calculation =
  //Calculate total value contributed for the current week where variable group is base
VAR __BasePerWeek =
    CALCULATE (
        SUM ( 'Table'[value contributed] ),
        ALL ( 'Table' ),
        'Table'[week] = EARLIER ( 'Table'[week] ),
        'Table'[variable group] = "base"
    )
  //Calculate total value contributed for the current week where variable group is not base
VAR __NotBasePerWeek =
    CALCULATE (
        SUM ( 'Table'[value contributed] ),
        ALL ( 'Table' ),
        'Table'[week] = EARLIER ( 'Table'[week] ),
        'Table'[variable group] <> "base"
    )
RETURN
    IF (
        __BasePerWeek < 0,
        DIVIDE ( 'Table'[value contributed], __NotBasePerWeek ) * 'Table'[actual value],
        'Table'[value contributed]
    )

 

 

Let me know if it works for you, and please mark myt response as a solution if so.


Did I answer your question? Mark my post as a solution!
My LinkedIn

View solution in original post

1 REPLY 1
Adescrit
Impactful Individual
Impactful Individual

Hi @Anonymous 

 

How about the formula below:

 

Calculation =
  //Calculate total value contributed for the current week where variable group is base
VAR __BasePerWeek =
    CALCULATE (
        SUM ( 'Table'[value contributed] ),
        ALL ( 'Table' ),
        'Table'[week] = EARLIER ( 'Table'[week] ),
        'Table'[variable group] = "base"
    )
  //Calculate total value contributed for the current week where variable group is not base
VAR __NotBasePerWeek =
    CALCULATE (
        SUM ( 'Table'[value contributed] ),
        ALL ( 'Table' ),
        'Table'[week] = EARLIER ( 'Table'[week] ),
        'Table'[variable group] <> "base"
    )
RETURN
    IF (
        __BasePerWeek < 0,
        DIVIDE ( 'Table'[value contributed], __NotBasePerWeek ) * 'Table'[actual value],
        'Table'[value contributed]
    )

 

 

Let me know if it works for you, and please mark myt response as a solution if so.


Did I answer your question? Mark my post as a solution!
My LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors